Class: Gergich::Capture::EslintCapture

Inherits:
BaseCapture show all
Defined in:
lib/gergich/capture/eslint_capture.rb

Constant Summary collapse

SEVERITY_MAP =
{ "error" => "error", "warning" => "warn" }.freeze

Instance Method Summary collapse

Methods inherited from BaseCapture

inherited, normalize_captor_class_name

Instance Method Details

#run(output) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gergich/capture/eslint_capture.rb', line 8

def run(output)
  # e.g. "  4:21  error  Missing semicolon  semi"
  error_pattern = %r{\s\s+(\d+):\d+\s+(\w+)\s+(.*?)\s+[\w/-]+\n}
  pattern = %r{            # Example:
    ^([^\n]+)\n            #   jsapp/models/user.js
    ((#{error_pattern})+)  #     4:21  error  Missing semicolon  semi
  }mx

  output.scan(pattern).map { |file, errors|
    errors.scan(error_pattern).map { |line, severity, error|
      severity = SEVERITY_MAP[severity]
      { path: file, message: error, source: "eslint", position: line.to_i,
        severity: severity }
    }
  }.compact.flatten
end