Class: RemLint::Offense
- Inherits:
-
Struct
- Object
- Struct
- RemLint::Offense
- Defined in:
- lib/remlint/offense.rb
Overview
One thing a rule found, at one place in one file.
The default rendering is path:line:column: severity: [Rule] message,
which vim's default errorformat reads, which GitHub Actions' problem
matchers read, and which sort orders correctly. The format is also
configurable, following puppet-lint, because the one thing every CI system
agrees on is that it wants a slightly different format.
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#line ⇒ Object
Returns the value of attribute line.
-
#message ⇒ Object
Returns the value of attribute message.
-
#path ⇒ Object
Returns the value of attribute path.
-
#rule ⇒ Object
Returns the value of attribute rule.
-
#severity ⇒ Object
Returns the value of attribute severity.
Instance Method Summary collapse
-
#at_least?(level) ⇒ Boolean
At or above the given severity, where "above" means closer to error.
- #error? ⇒ Boolean
-
#format_with(template) ⇒ Object
%{path},%{line},%{column},%{severity},%{rule},%{message}. -
#initialize(path:, line:, rule:, message:, column: 1, severity: "warning") ⇒ Offense
constructor
A new instance of Offense.
- #severity_rank ⇒ Object
-
#sort_key ⇒ Object
File, then position, then severity: the order someone reads them in.
- #to_s ⇒ Object
Constructor Details
#initialize(path:, line:, rule:, message:, column: 1, severity: "warning") ⇒ Offense
Returns a new instance of Offense.
29 30 31 |
# File 'lib/remlint/offense.rb', line 29 def initialize(path:, line:, rule:, message:, column: 1, severity: "warning") super end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def column @column end |
#line ⇒ Object
Returns the value of attribute line
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def line @line end |
#message ⇒ Object
Returns the value of attribute message
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def @message end |
#path ⇒ Object
Returns the value of attribute path
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def path @path end |
#rule ⇒ Object
Returns the value of attribute rule
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def rule @rule end |
#severity ⇒ Object
Returns the value of attribute severity
20 21 22 |
# File 'lib/remlint/offense.rb', line 20 def severity @severity end |
Instance Method Details
#at_least?(level) ⇒ Boolean
At or above the given severity, where "above" means closer to error.
42 43 44 |
# File 'lib/remlint/offense.rb', line 42 def at_least?(level) severity_rank <= (SEVERITIES.index(level) || SEVERITIES.length) end |
#error? ⇒ Boolean
37 38 39 |
# File 'lib/remlint/offense.rb', line 37 def error? severity == "error" end |
#format_with(template) ⇒ Object
%{path}, %{line}, %{column}, %{severity}, %{rule}, %{message}.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/remlint/offense.rb', line 51 def format_with(template) format( template, path: path, line: line, column: column, severity: severity, rule: rule, message: , ) end |
#severity_rank ⇒ Object
33 34 35 |
# File 'lib/remlint/offense.rb', line 33 def severity_rank SEVERITIES.index(severity) || SEVERITIES.length end |
#sort_key ⇒ Object
File, then position, then severity: the order someone reads them in.
64 65 66 |
# File 'lib/remlint/offense.rb', line 64 def sort_key [path, line, column, severity_rank, rule] end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/remlint/offense.rb', line 46 def to_s format_with("%{path}:%{line}:%{column}: %{severity}: [%{rule}] %{message}") end |