Class: ERBLint::Offense
- Inherits:
-
Object
- Object
- ERBLint::Offense
- Defined in:
- lib/erb_lint/offense.rb
Overview
Defines common functionality available to all linters.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#disabled ⇒ Object
writeonly
Sets the attribute disabled.
-
#linter ⇒ Object
readonly
Returns the value of attribute linter.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#source_range ⇒ Object
readonly
Returns the value of attribute source_range.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #column ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(linter, source_range, message, context = nil, severity = nil) ⇒ Offense
constructor
A new instance of Offense.
- #inspect ⇒ Object
- #last_column ⇒ Object
- #last_line ⇒ Object
- #length ⇒ Object
- #line_number ⇒ Object
- #line_range ⇒ Object
- #simple_name ⇒ Object
- #to_cached_offense_hash ⇒ Object
Constructor Details
#initialize(linter, source_range, message, context = nil, severity = nil) ⇒ Offense
Returns a new instance of Offense.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/erb_lint/offense.rb', line 8 def initialize(linter, source_range, , context = nil, severity = nil) unless source_range.is_a?(Parser::Source::Range) raise ArgumentError, "expected Parser::Source::Range for arg 2" end @linter = linter @source_range = source_range @message = @context = context @severity = severity @disabled = false end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/erb_lint/offense.rb', line 6 def context @context end |
#disabled=(value) ⇒ Object (writeonly)
Sets the attribute disabled
48 49 50 |
# File 'lib/erb_lint/offense.rb', line 48 def disabled=(value) @disabled = value end |
#linter ⇒ Object (readonly)
Returns the value of attribute linter.
6 7 8 |
# File 'lib/erb_lint/offense.rb', line 6 def linter @linter end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/erb_lint/offense.rb', line 6 def @message end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
6 7 8 |
# File 'lib/erb_lint/offense.rb', line 6 def severity @severity end |
#source_range ⇒ Object (readonly)
Returns the value of attribute source_range.
6 7 8 |
# File 'lib/erb_lint/offense.rb', line 6 def source_range @source_range end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/erb_lint/offense.rb', line 32 def ==(other) other.class <= ERBLint::Offense && other.linter == linter && other.source_range == source_range && other. == && other.severity == severity end |
#column ⇒ Object
54 55 56 |
# File 'lib/erb_lint/offense.rb', line 54 def column source_range.column end |
#disabled? ⇒ Boolean
50 51 52 |
# File 'lib/erb_lint/offense.rb', line 50 def disabled? @disabled end |
#inspect ⇒ Object
25 26 27 28 29 30 |
# File 'lib/erb_lint/offense.rb', line 25 def inspect "#<#{self.class.name} linter=#{linter.class.name} " \ "source_range=#{source_range.begin_pos}...#{source_range.end_pos} " \ "message=#{}> " \ "severity=#{severity}" end |
#last_column ⇒ Object
66 67 68 |
# File 'lib/erb_lint/offense.rb', line 66 def last_column source_range.last_column end |
#last_line ⇒ Object
62 63 64 |
# File 'lib/erb_lint/offense.rb', line 62 def last_line source_range.last_line end |
#length ⇒ Object
70 71 72 |
# File 'lib/erb_lint/offense.rb', line 70 def length source_range.length end |
#line_number ⇒ Object
44 45 46 |
# File 'lib/erb_lint/offense.rb', line 44 def line_number line_range.begin end |
#line_range ⇒ Object
40 41 42 |
# File 'lib/erb_lint/offense.rb', line 40 def line_range Range.new(source_range.line, source_range.last_line) end |
#simple_name ⇒ Object
58 59 60 |
# File 'lib/erb_lint/offense.rb', line 58 def simple_name linter.class.simple_name end |
#to_cached_offense_hash ⇒ Object
21 22 23 |
# File 'lib/erb_lint/offense.rb', line 21 def to_cached_offense_hash ERBLint::CachedOffense.new_from_offense(self).to_h end |