Class: Yard::Lint::Validators::Documentation::LineLength::Parser
- Inherits:
-
Parsers::Base
- Object
- Parsers::Base
- Yard::Lint::Validators::Documentation::LineLength::Parser
- Defined in:
- lib/yard/lint/validators/documentation/line_length/parser.rb
Overview
Parses LineLength validator output into structured violation hashes.
Expected format (two lines per object with violations):
file.rb:OBJECT_LINE: ObjectName
MAX_LENGTH|LINE_NO:LENGTH|LINE_NO:LENGTH|...
Instance Method Summary collapse
-
#call(output) ⇒ Array<Hash>
Array of violation hashes.
Methods inherited from Parsers::Base
Instance Method Details
#call(output) ⇒ Array<Hash>
Returns array of violation hashes.
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 55 56 57 58 59 |
# File 'lib/yard/lint/validators/documentation/line_length/parser.rb', line 16 def call(output, **) return [] if output.nil? || output.empty? violations = [] lines = output.lines.map(&:chomp) i = 0 while i < lines.size line = lines[i] if (location_match = line.match(/^(.+):(\d+): (.+)$/)) file_path = location_match[1] object_line = location_match[2].to_i object_name = location_match[3] i += 1 next unless i < lines.size parts = lines[i].split('|') next if parts.empty? # First token is max_length, remainder are line_no:length pairs max_length = parts.shift.to_i parts.each do |part| line_no, length = part.split(':', 2) next unless line_no && length violations << { location: file_path, line: line_no.to_i, object_line: object_line, object_name: object_name, length: length.to_i, max_length: max_length } end end i += 1 end violations end |