Class: Gergich::Capture::StylelintCapture

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

Constant Summary collapse

SEVERITY_MAP =

stylelint is a css linter github.com/stylelint/stylelint

example full output: app/stylesheets/base/_print.scss

3:17  ✖  Unexpected invalid hex color "#owiehfi"   color-no-invalid-hex
3:17  ⚠  Expected "#owiehfi" to be "#OWIEHFI"      color-hex-case

app/stylesheets/base/_variables.scss

 2:15  ✖  Unexpected invalid hex color "#2D3B4"   color-no-invalid-hex
30:15  ⚠  Expected "#2d3b4a" to be "#2D3B4A"      color-hex-case
{
  "" => "error",
  "" => "warn",
  "" => "info"
}.freeze
FILE_PATH_PATTERN =

example file line: app/stylesheets/base/_variables.scss

/([^\n]+)\n/.freeze
ERROR_PATTERN =

example error line:

1:15  ✖  Unexpected invalid hex color "#2D3B4"   color-no-invalid-hex
/^\s+(\d+):\d+\s+(✖|⚠|ℹ)\s+(.*?)\s\s+[^\n]+\n/.freeze
PATTERN =
/#{FILE_PATH_PATTERN}((#{ERROR_PATTERN})+)/.freeze

Instance Method Summary collapse

Methods inherited from BaseCapture

inherited, normalize_captor_class_name

Instance Method Details

#run(output) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gergich/capture/stylelint_capture.rb', line 34

def run(output)
  output.scan(PATTERN).map { |file, errors|
    errors.scan(ERROR_PATTERN).map { |line, severity, error|
      severity = SEVERITY_MAP[severity]
      {
        path: file,
        message: error,
        source: "stylelint",
        position: line.to_i,
        severity: severity
      }
    }
  }.flatten.compact
end