Class: Gergich::Capture::YamllintCapture

Inherits:
BaseCapture show all
Defined in:
lib/gergich/capture/yamllint_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
24
25
26
27
28
# File 'lib/gergich/capture/yamllint_capture.rb', line 8

def run(output)
  # e.g. "  9:5       error    string value redundantly  (quoted-strings)"
  error_pattern = %r{\s\s+(\d+):\d+\s+(\w+)\s+(.*?)\s+\([\w/-]+\)\n}
  pattern = %r{            # Example:
    ^./([^\n]+)\n         #   ./api/config/lti/development/config.yml
    ((#{error_pattern})+)  #     9:5       error    string value redundantly  (quoted-strings)
  }mx

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