Class: Yard::Lint::Validators::Documentation::EmptyCommentLine::Parser

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

Overview

Parses YARD output for empty comment line violations

Instance Method Summary collapse

Methods inherited from Parsers::Base

#match

Instance Method Details

#call(output) ⇒ Array<Hash>

Parse YARD output into structured violations

Parameters:

  • output (String)

    raw YARD output

Returns:

  • (Array<Hash>)

    array of violation hashes



13
14
15
16
17
18
19
20
21
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
52
53
54
# File 'lib/yard/lint/validators/documentation/empty_comment_line/parser.rb', line 13

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

  violations = []
  lines = output.lines.map(&:chomp)

  i = 0
  while i < lines.size
    line = lines[i]

    # Match location line: "file:line: object_name"
    if (location_match = line.match(/^(.+):(\d+): (.+)$/))
      file_path = location_match[1]
      object_line = location_match[2].to_i
      object_name = location_match[3]

      # Next line contains violation details
      i += 1
      next unless i < lines.size

      # Parse violations: "leading:5|trailing:10"
      violation_parts = lines[i].split('|')

      violation_parts.each do |part|
        type, line_num = part.split(':', 2)
        next unless type && line_num

        violations << {
          location: file_path,
          line: line_num.to_i,
          object_line: object_line,
          object_name: object_name,
          violation_type: type
        }
      end
    end

    i += 1
  end

  violations
end