Class: Browsable::Report
- Inherits:
-
Object
- Object
- Browsable::Report
- Defined in:
- lib/browsable/report.rb
Overview
The aggregated result of an audit: every Finding produced by every analyzer, plus a record of any analyzer or source that was skipped.
A Report makes no decisions. It tells the user what their code requires and how that compares against their target; the formatters present it and the exit-code policy lives entirely in the caller’s chosen –fail-on value.
Defined Under Namespace
Classes: Skip, Suggestion
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#skips ⇒ Object
readonly
Returns the value of attribute skips.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #as_json ⇒ Object
- #empty? ⇒ Boolean
- #errors ⇒ Object
-
#exit_code(fail_on:) ⇒ Object
Exit code implementing the –fail-on policy.
-
#findings_by_file ⇒ Object
Findings grouped by file path, files sorted, findings sorted by position.
- #infos ⇒ Object
-
#initialize(findings: [], skips: [], notes: [], policies: [], target: nil, root: nil, config_file: nil) ⇒ Report
constructor
A new instance of Report.
-
#suggestion ⇒ Object
An allow_browser line that raises the offending browsers just enough to cover every below-target error, leaving the other browsers untouched.
- #warnings ⇒ Object
Constructor Details
#initialize(findings: [], skips: [], notes: [], policies: [], target: nil, root: nil, config_file: nil) ⇒ Report
Returns a new instance of Report.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/browsable/report.rb', line 24 def initialize(findings: [], skips: [], notes: [], policies: [], target: nil, root: nil, config_file: nil) @findings = findings @skips = skips @notes = notes @policies = policies @target = target @root = root @config_file = config_file end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def config_file @config_file end |
#findings ⇒ Object (readonly)
Returns the value of attribute findings.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def findings @findings end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def notes @notes end |
#policies ⇒ Object (readonly)
Returns the value of attribute policies.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def policies @policies end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def root @root end |
#skips ⇒ Object (readonly)
Returns the value of attribute skips.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def skips @skips end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
18 19 20 |
# File 'lib/browsable/report.rb', line 18 def target @target end |
Instance Method Details
#as_json ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/browsable/report.rb', line 74 def as_json { target: target&.as_json, notes: notes, summary: { errors: errors.size, warnings: warnings.size, infos: infos.size, files: findings_by_file.size }, findings: findings.map(&:as_json), skips: skips.map { |skip| { kind: skip.kind.to_s, reason: skip.reason } }, policies: policies.map { |policy| policy_as_json(policy) }, suggested_policy: suggestion && { line: suggestion.line, bumps: suggestion.bumps } } end |
#empty? ⇒ Boolean
39 |
# File 'lib/browsable/report.rb', line 39 def empty? = findings.empty? |
#errors ⇒ Object
35 |
# File 'lib/browsable/report.rb', line 35 def errors = findings.select(&:error?) |
#exit_code(fail_on:) ⇒ Object
Exit code implementing the –fail-on policy.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/browsable/report.rb', line 51 def exit_code(fail_on:) case fail_on.to_s when "warning" errors.any? || warnings.any? ? 1 : 0 when "error" errors.any? ? 1 : 0 else 0 end end |
#findings_by_file ⇒ Object
Findings grouped by file path, files sorted, findings sorted by position.
42 43 44 45 46 47 48 |
# File 'lib/browsable/report.rb', line 42 def findings_by_file findings .group_by(&:file) .sort_by(&:first) .to_h .transform_values { |group| group.sort_by { |f| [f.line, f.column] } } end |
#infos ⇒ Object
37 |
# File 'lib/browsable/report.rb', line 37 def infos = findings.select(&:info?) |
#suggestion ⇒ Object
An allow_browser line that raises the offending browsers just enough to cover every below-target error, leaving the other browsers untouched.
Returns nil when no error carries comparable version data — CSS/JS findings come from stylelint/eslint, which do not expose exact versions, so a suggestion can only be derived from HTML/ERB findings.
68 69 70 71 72 |
# File 'lib/browsable/report.rb', line 68 def suggestion return @suggestion if defined?(@suggestion) @suggestion = build_suggestion end |
#warnings ⇒ Object
36 |
# File 'lib/browsable/report.rb', line 36 def warnings = findings.select(&:warning?) |