Class: Mdlint::Linter::Violation

Inherits:
Object
  • Object
show all
Defined in:
lib/mdlint/linter/violation.rb,
sig/mdlint.rbs,
sig/internal.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule_id:, message:, line:, column: nil, severity: :warning, fixable: false) ⇒ Violation

Returns a new instance of Violation.

Parameters:

  • rule_id: (String)
  • message: (String)
  • line: (Integer)
  • column: (Integer, nil) (defaults to: nil)
  • severity: (Symbol) (defaults to: :warning)
  • fixable: (Boolean) (defaults to: false)


8
9
10
11
12
13
14
15
# File 'lib/mdlint/linter/violation.rb', line 8

def initialize(rule_id:, message:, line:, column: nil, severity: :warning, fixable: false)
  @rule_id = rule_id
  @message = message
  @line = line
  @column = column
  @severity = severity.to_sym
  @fixable = fixable
end

Instance Attribute Details

#columnInteger? (readonly)

Returns the value of attribute column.

Returns:

  • (Integer, nil)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def column
  @column
end

#fixableBoolean (readonly)

Returns the value of attribute fixable.

Returns:

  • (Boolean)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def fixable
  @fixable
end

#lineInteger (readonly)

Returns the value of attribute line.

Returns:

  • (Integer)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def line
  @line
end

#messageString (readonly)

Returns the value of attribute message.

Returns:

  • (String)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def message
  @message
end

#rule_idString (readonly)

Returns the value of attribute rule_id.

Returns:

  • (String)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def rule_id
  @rule_id
end

#severitySymbol (readonly)

Returns the value of attribute severity.

Returns:

  • (Symbol)


6
7
8
# File 'lib/mdlint/linter/violation.rb', line 6

def severity
  @severity
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mdlint/linter/violation.rb', line 26

def error?
  @severity == :error
end

#fixable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/mdlint/linter/violation.rb', line 22

def fixable?
  @fixable
end

#info?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mdlint/linter/violation.rb', line 34

def info?
  @severity == :info
end

#to_hHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


38
39
40
41
42
43
44
45
46
47
# File 'lib/mdlint/linter/violation.rb', line 38

def to_h
  {
    rule_id: @rule_id,
    message: @message,
    line: @line,
    column: @column,
    severity: @severity,
    fixable: @fixable
  }
end

#to_sString

Returns:

  • (String)


17
18
19
20
# File 'lib/mdlint/linter/violation.rb', line 17

def to_s
  location = column ? "#{line}:#{column}" : line.to_s
  "[#{rule_id}] #{location}: #{message}"
end

#warning?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mdlint/linter/violation.rb', line 30

def warning?
  @severity == :warning
end