Class: Yard::Lint::Executor::WarningDispatcher

Inherits:
Object
  • Object
show all
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

Instance Method Details

#dispatch(warnings) ⇒ Hash{String => Array<String>}

Dispatch warnings to appropriate validators

Parameters:

  • warnings (Array<String>)

    raw warning messages from YARD

Returns:

  • (Hash{String => Array<String>})

    warnings grouped by validator name



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)

Parameters:

  • warnings (Array<String>)

    warnings for this validator

Returns:

  • (Hash)

    result hash with :stdout, :stderr, :exit_code keys



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

Parameters:

  • warning (String)

    raw warning message

Returns:

  • (String)

    formatted warning



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)

Parameters:

  • validator_name (String)

    full validator name

Returns:

  • (Boolean)


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_namesArray<String>

Get all warning validator names

Returns:

  • (Array<String>)


73
74
75
# File 'lib/yard/lint/executor/warning_dispatcher.rb', line 73

def warning_validator_names
  PATTERNS.keys
end