Class: Yard::Lint::Results::Aggregate
- Inherits:
-
Object
- Object
- Yard::Lint::Results::Aggregate
- Defined in:
- lib/yard/lint/results/aggregate.rb
Overview
Aggregates multiple validator results into a single result object
Constant Summary collapse
- SEVERITY_ERROR =
Error severity level constant
'error'- SEVERITY_WARNING =
Warning severity level constant
'warning'- SEVERITY_CONVENTION =
Convention severity level constant
'convention'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#clean? ⇒ Boolean
Check if there are no offenses.
-
#count ⇒ Integer
Total number of offenses.
-
#documentation_coverage ⇒ Hash
Calculate documentation coverage statistics.
-
#exit_code ⇒ Integer
Determine exit code based on configured fail_on_severity Uses the config object stored during initialization.
-
#initialize(results, config = nil, files = nil) ⇒ Aggregate
constructor
Initialize aggregate result with array of validator results.
-
#offenses ⇒ Array<Hash>
Get all offenses from all validators.
-
#statistics ⇒ Hash
Get offense statistics by severity.
Constructor Details
#initialize(results, config = nil, files = nil) ⇒ Aggregate
Initialize aggregate result with array of validator results
22 23 24 25 26 |
# File 'lib/yard/lint/results/aggregate.rb', line 22 def initialize(results, config = nil, files = nil) @results = Array(results) @config = config @files = Array(files) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/yard/lint/results/aggregate.rb', line 16 def config @config end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
16 17 18 |
# File 'lib/yard/lint/results/aggregate.rb', line 16 def files @files end |
Instance Method Details
#clean? ⇒ Boolean
Check if there are no offenses
42 43 44 |
# File 'lib/yard/lint/results/aggregate.rb', line 42 def clean? offenses.empty? end |
#count ⇒ Integer
Total number of offenses
36 37 38 |
# File 'lib/yard/lint/results/aggregate.rb', line 36 def count offenses.count end |
#documentation_coverage ⇒ Hash
Calculate documentation coverage statistics
67 68 69 70 71 72 73 74 |
# File 'lib/yard/lint/results/aggregate.rb', line 67 def documentation_coverage return @documentation_coverage if defined?(@documentation_coverage) return nil unless @config && !@files.empty? calculator = StatsCalculator.new(@config, @files) @documentation_coverage = calculator.calculate end |
#exit_code ⇒ Integer
Determine exit code based on configured fail_on_severity Uses the config object stored during initialization
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/yard/lint/results/aggregate.rb', line 79 def exit_code # Check minimum coverage requirement first if @config&.min_coverage && documentation_coverage && documentation_coverage[:coverage] < @config.min_coverage return 1 end return 0 if offenses.empty? return 0 unless @config # No config means don't fail fail_on = @config.fail_on_severity case fail_on when SEVERITY_ERROR statistics[:error].positive? ? 1 : 0 when SEVERITY_WARNING (statistics[:error] + statistics[:warning]).positive? ? 1 : 0 when SEVERITY_CONVENTION offenses.any? ? 1 : 0 else 0 end end |
#offenses ⇒ Array<Hash>
Get all offenses from all validators
30 31 32 |
# File 'lib/yard/lint/results/aggregate.rb', line 30 def offenses @results.flat_map(&:offenses) end |
#statistics ⇒ Hash
Get offense statistics by severity
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yard/lint/results/aggregate.rb', line 48 def statistics stats = { error: 0, warning: 0, convention: 0, total: 0 } offenses.each do |offense| severity = offense[:severity].to_sym stats[severity] += 1 if stats.key?(severity) stats[:total] += 1 end stats end |