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, severity = nil) ⇒ Offense

Returns a new instance of Offense.



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

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

#severityObject (readonly)

Returns the value of attribute severity.



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

def severity
  @severity
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



26
27
28
29
30
31
32
# File 'lib/erb_lint/offense.rb', line 26

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

#columnObject



42
43
44
# File 'lib/erb_lint/offense.rb', line 42

def column
  source_range.column
end

#inspectObject



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

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

#line_numberObject



38
39
40
# File 'lib/erb_lint/offense.rb', line 38

def line_number
  line_range.begin
end

#line_rangeObject



34
35
36
# File 'lib/erb_lint/offense.rb', line 34

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