Class: ERBLint::Offense

Inherits:
Object
  • Object
show all
Defined in:
lib/erb_lint/offense.rb

Overview

Defines common functionality available to all linters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(linter, source_range, message, context = nil) ⇒ Offense

Returns a new instance of Offense.



8
9
10
11
12
13
14
15
16
# File 'lib/erb_lint/offense.rb', line 8

def initialize(linter, source_range, message, context = 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 = message
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/erb_lint/offense.rb', line 6

def context
  @context
end

#linterObject (readonly)

Returns the value of attribute linter.



6
7
8
# File 'lib/erb_lint/offense.rb', line 6

def linter
  @linter
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/erb_lint/offense.rb', line 6

def message
  @message
end

#source_rangeObject (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



24
25
26
27
28
29
# File 'lib/erb_lint/offense.rb', line 24

def ==(other)
  other.class <= ERBLint::Offense &&
    other.linter == linter &&
    other.source_range == source_range &&
    other.message == message
end

#inspectObject



18
19
20
21
22
# File 'lib/erb_lint/offense.rb', line 18

def inspect
  "#<#{self.class.name} linter=#{linter.class.name} "\
    "source_range=#{source_range.begin_pos}...#{source_range.end_pos} "\
    "message=#{message}>"
end

#line_rangeObject



31
32
33
# File 'lib/erb_lint/offense.rb', line 31

def line_range
  Range.new(source_range.line, source_range.last_line)
end