Class: Yard::Lint::Validators::Documentation::DuplicateNamespaceComment::Parser

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

Overview

Extracts duplicate namespace documentation offenses from raw collector output. Each line has the form "file:line: Namespace\tsite|site|...\tconflict" where conflict is either 'same' or 'differ'.

Examples:

Output format (skip-lint)

/a.rb:6: Foo::Bar\t/a.rb:6|/b.rb:6\tsame

Constant Summary collapse

LINE_REGEX =

Parses the "file:line: Namespace" head of an offense line. The namespace path uses '::' and never ': ', so the final ": " is an unambiguous separator.

/\A(.+):(\d+): (.+)\z/

Instance Method Summary collapse

Methods inherited from Parsers::Base

#match

Instance Method Details

#call(output) ⇒ Array<Hash>

Returns offense hashes with location/line/namespace/sites/conflict.

Parameters:

  • output (String)

    raw collector output, one offense per line

Returns:

  • (Array<Hash>)

    offense hashes with location/line/namespace/sites/conflict



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yard/lint/validators/documentation/duplicate_namespace_comment/parser.rb', line 20

def call(output)
  return [] if output.nil? || output.empty?

  output.split("\n").filter_map do |line|
    head, sites, conflict = line.split("\t")
    next unless head

    match = head.match(LINE_REGEX)
    next unless match

    {
      location: match[1],
      line: match[2].to_i,
      namespace: match[3],
      sites: (sites || '').split('|'),
      conflict: conflict
    }
  end
end