Class: Yard::Lint::Executor::WarningDispatcher
- Inherits:
-
Object
- Object
- Yard::Lint::Executor::WarningDispatcher
- Defined in:
- lib/yard/lint/executor/warning_dispatcher.rb
Overview
Routes captured YARD warnings to appropriate warning validators. Uses the same regex patterns as the existing parsers to ensure consistency.
Constant Summary collapse
- PATTERNS =
Patterns matching the ‘general’ regexps from each warning validator’s parser. These patterns identify which validator should handle each warning.
{ 'Warnings/UnknownTag' => /^\[warn\]: Unknown tag.*@.*near line/, 'Warnings/UnknownParameterName' => /^\[warn\]: @param tag has unknown parameter name/, 'Warnings/DuplicatedParameterName' => /^\[warn\]: @param tag has duplicate parameter name/, 'Warnings/UnknownDirective' => /^\[warn\]: Unknown directive.*@!.*near line/, 'Warnings/InvalidTagFormat' => /^\[warn\]: Invalid tag format/, 'Warnings/InvalidDirectiveFormat' => /^\[warn\]: Invalid directive format/ }.freeze
Instance Method Summary collapse
-
#dispatch(warnings) ⇒ Hash{String => Array<String>}
Dispatch warnings to appropriate validators.
-
#format_for_validator(warnings) ⇒ Hash
Build result hash for a validator from its dispatched warnings The warnings are put in stdout because the ResultBuilder reads from stdout (in shell mode, YARD outputs warnings to stderr but they get combined).
-
#format_warning(warning) ⇒ String
Format a raw warning to match YARD’s stderr output format.
-
#warning_validator?(validator_name) ⇒ Boolean
Check if a validator is a warning validator (handled by dispatcher).
-
#warning_validator_names ⇒ Array<String>
Get all warning validator names.
Instance Method Details
#dispatch(warnings) ⇒ Hash{String => Array<String>}
Dispatch warnings to appropriate validators
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 23 def dispatch(warnings) grouped = Hash.new { |h, k| h[k] = [] } warnings.each do |warning| # Format the warning as YARD outputs it formatted = format_warning(warning) PATTERNS.each do |validator_name, pattern| if formatted.match?(pattern) grouped[validator_name] << formatted break end end end grouped end |
#format_for_validator(warnings) ⇒ Hash
Build result hash for a validator from its dispatched warnings The warnings are put in stdout because the ResultBuilder reads from stdout (in shell mode, YARD outputs warnings to stderr but they get combined)
56 57 58 59 60 61 62 |
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 56 def format_for_validator(warnings) { stdout: warnings.join("\n"), stderr: '', exit_code: 0 } end |
#format_warning(warning) ⇒ String
Format a raw warning to match YARD’s stderr output format
44 45 46 47 48 49 |
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 44 def format_warning(warning) # If the warning already has [warn]: prefix, return as-is return warning if warning.start_with?('[warn]:') "[warn]: #{warning}" end |
#warning_validator?(validator_name) ⇒ Boolean
Check if a validator is a warning validator (handled by dispatcher)
67 68 69 |
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 67 def warning_validator?(validator_name) PATTERNS.key?(validator_name) end |
#warning_validator_names ⇒ Array<String>
Get all warning validator names
73 74 75 |
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 73 def warning_validator_names PATTERNS.keys end |