Class: SlimLint::Lint

Inherits:
Object
  • Object
show all
Defined in:
lib/slim_lint/lint.rb

Overview

Contains information about a problem or issue with a Slim document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(linter, filename, line, message, severity = :warning, correction: nil) ⇒ Lint

Creates a new lint.

Parameters:

  • linter (SlimLint::Linter)
  • filename (String)
  • line (Fixnum)
  • message (String)
  • severity (Symbol) (defaults to: :warning)
  • correction (Proc, nil) (defaults to: nil)

    maps a line of source to its corrected version



36
37
38
39
40
41
42
43
44
45
# File 'lib/slim_lint/lint.rb', line 36

def initialize(linter, filename, line, message, severity = :warning, # rubocop:disable Metrics/ParameterLists
               correction: nil)
  @linter     = linter
  @filename   = filename
  @line       = line || 0
  @message    = message
  @severity   = severity
  @correction = correction
  @corrected  = false
end

Instance Attribute Details

#correctedBoolean

Returns whether this lint's correction has been applied.

Returns:

  • (Boolean)

    whether this lint's correction has been applied



26
27
28
# File 'lib/slim_lint/lint.rb', line 26

def corrected
  @corrected
end

#correctionProc? (readonly)

Returns maps a line of source to its corrected version, or nil if this lint has no known automatic correction.

Returns:

  • (Proc, nil)

    maps a line of source to its corrected version, or nil if this lint has no known automatic correction



23
24
25
# File 'lib/slim_lint/lint.rb', line 23

def correction
  @correction
end

#filenameString (readonly)

Returns file path to which the lint applies.

Returns:

  • (String)

    file path to which the lint applies



7
8
9
# File 'lib/slim_lint/lint.rb', line 7

def filename
  @filename
end

#lineString (readonly)

Returns line number of the file the lint corresponds to.

Returns:

  • (String)

    line number of the file the lint corresponds to



10
11
12
# File 'lib/slim_lint/lint.rb', line 10

def line
  @line
end

#linterSlimLint::Linter (readonly)

Returns linter that reported the lint.

Returns:



13
14
15
# File 'lib/slim_lint/lint.rb', line 13

def linter
  @linter
end

#messageString (readonly)

Returns error/warning message to display to user.

Returns:

  • (String)

    error/warning message to display to user



16
17
18
# File 'lib/slim_lint/lint.rb', line 16

def message
  @message
end

#severitySymbol (readonly)

Returns whether this lint is a warning or an error.

Returns:

  • (Symbol)

    whether this lint is a warning or an error



19
20
21
# File 'lib/slim_lint/lint.rb', line 19

def severity
  @severity
end

Instance Method Details

#correctable?Boolean

Return whether this lint has a known automatic correction.

Returns:

  • (Boolean)


57
58
59
# File 'lib/slim_lint/lint.rb', line 57

def correctable?
  !@correction.nil?
end

#corrected?Boolean

Return whether this lint's correction has been applied.

Returns:

  • (Boolean)


64
65
66
# File 'lib/slim_lint/lint.rb', line 64

def corrected?
  @corrected
end

#error?Boolean

Return whether this lint has a severity of error.

Returns:

  • (Boolean)


50
51
52
# File 'lib/slim_lint/lint.rb', line 50

def error?
  @severity == :error
end