Class: Gergich::Capture::SwiftlintCapture

Inherits:
BaseCapture
  • Object
show all
Defined in:
lib/gergich/capture/swiftlint_capture.rb

Constant Summary collapse

SEVERITY_MAP =

See SeverityLevelsConfiguration.swift

{
  "error" => "error",  # console description
  "warning" => "warn",
  "w" => "warn",       # short console description
  "w/e" => "error"
}.freeze

Instance Method Summary collapse

Methods inherited from BaseCapture

inherited, normalize_captor_class_name

Instance Method Details

#run(output) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gergich/capture/swiftlint_capture.rb', line 14

def run(output)
  # rubocop:disable Layout/LineLength
  #
  # Example:
  # /path/to/My.swift:13:22: warning: Colon Violation: Colons should be next to the identifier when specifying a type. (colon)
  # /path/to/Fail.swift:80: warning: Line Length Violation: Line should be 100 characters or less: currently 108 characters (line_length)
  #
  # rubocop:enable Layout/LineLength
  pattern = /
    ^([^:\n]+):(\d+)(?::\d+)?:\s(\w+):\s(.*?)\n
  /mx

  output.scan(pattern).map { |file, line, severity, error, _context|
    { path: file, message: error, source: "swiftlint",
      position: line.to_i, severity: SEVERITY_MAP[severity] }
  }.compact
end