Class: Yard::Lint::Validators::Documentation::TextSubstitution::Parser

Inherits:
Parsers::Base
  • Object
show all
Defined in:
lib/yard/lint/validators/documentation/text_substitution/parser.rb

Overview

Parses TextSubstitution validator output into structured violation hashes.

Wire format (four lines per violation):

file.rb:LINE: ObjectTitle
forbidden
replacement
line_offset|line_text

forbidden and replacement occupy their own lines so they may contain any character, including the pipe delimiter used in the last field.

Instance Method Summary collapse

Methods inherited from Parsers::Base

#match

Instance Method Details

#call(yard_output, **_kwargs) ⇒ Array<Hash>

Returns array with violation details.

Parameters:

  • yard_output (String)

    raw collector output from the validator

  • _kwargs (Hash)

    a customizable set of options

Options Hash (**_kwargs):

  • :unused (Object)

    accepts no options (reserved for future use)

Returns:

  • (Array<Hash>)

    array with violation details



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/yard/lint/validators/documentation/text_substitution/parser.rb', line 22

def call(yard_output, **_kwargs)
  return [] if yard_output.nil? || yard_output.strip.empty?

  # Do not strip lines — forbidden/replacement may have significant whitespace
  lines = yard_output.split("\n")
  violations = []

  lines.each_slice(4) do |location_line, forbidden_line, replacement_line, details_line|
    next unless location_line && forbidden_line && replacement_line && details_line

    location_match = location_line.strip.match(/^(.+):(\d+): (.+)$/)
    next unless location_match

    # line_offset is always numeric; split on first pipe only so line_text may contain pipes
    line_offset_str, line_text = details_line.split('|', 2)
    next unless line_offset_str

    violations << {
      location:    location_match[1],
      line:        location_match[2].to_i,
      object_name: location_match[3],
      forbidden:   forbidden_line,
      replacement: replacement_line,
      line_offset: line_offset_str.to_i,
      line_text:   line_text || ''
    }
  end

  violations
end