Class: Lintrunner::Parser::Eslint

Inherits:
Base
  • Object
show all
Defined in:
lib/lintrunner/parser/eslint.rb

Instance Method Summary collapse

Instance Method Details

#parse(output, exit_code, options = {}) ⇒ Object

Example output of eslint (using the compact formatter): app/javascripts/delivery_page/components/add_guests.js: line 256, col 5, Error - Missing semicolon. (semi) app/javascripts/delivery_page/components/add_guests.js: line 277, col 18, Error - Props should be sorted alphabetically (react/jsx-sort-props)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lintrunner/parser/eslint.rb', line 8

def parse(output, exit_code, options = {})
  return [] unless exit_code == 1

  messages = []
  output.each_line do |line|

    match = /(?<filename>.*): line (?<line>\d*), .*Error - (?<description>.*) \((?<name>.*)\)/.match(line)
    if match
      messages << Lintrunner::Message.new(
        filename: options[:filename] || match[:filename],
        line: match["line"].to_i,
        name: match["name"],
        description: match["description"])
    end
  end
  messages
end