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 Identical offenses are reported once: objects sharing one docstring (e.g. the reader and writer generated by attr_accessor) produce the same offense for each generated method.
-
#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
47 48 49 |
# File 'lib/yard/lint/results/aggregate.rb', line 47 def clean? offenses.empty? end |
#count ⇒ Integer
Total number of offenses
41 42 43 |
# File 'lib/yard/lint/results/aggregate.rb', line 41 def count offenses.count end |
#documentation_coverage ⇒ Hash
Calculate documentation coverage statistics
72 73 74 75 76 77 78 79 |
# File 'lib/yard/lint/results/aggregate.rb', line 72 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/yard/lint/results/aggregate.rb', line 84 def exit_code # Check minimum coverage requirement first if @config&.min_coverage coverage = documentation_coverage # Fail safe: if a minimum is required but coverage could not be # determined (e.g. the YARD stats subprocess failed), do not pass. return 1 if coverage.nil? || coverage[:coverage] < @config.min_coverage 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 # Exclude 'never'-severity offenses, which are meant to run without # ever failing the build (they are also omitted from #statistics). (statistics[:error] + statistics[:warning] + statistics[:convention]).positive? ? 1 : 0 else 0 end end |
#offenses ⇒ Array<Hash>
Get all offenses from all validators Identical offenses are reported once: objects sharing one docstring (e.g. the reader and writer generated by attr_accessor) produce the same offense for each generated method
33 34 35 36 37 |
# File 'lib/yard/lint/results/aggregate.rb', line 33 def offenses @offenses ||= @results.flat_map(&:offenses).uniq do |offense| offense.values_at(:validator, :name, :location, :location_line, :message) end end |
#statistics ⇒ Hash
Get offense statistics by severity
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard/lint/results/aggregate.rb', line 53 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 |