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
18
19
# 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
  @disabled = false
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

#disabled=(value) ⇒ Object (writeonly)

Sets the attribute disabled

Parameters:

  • value

    the value to set the attribute disabled to.



48
49
50
# File 'lib/erb_lint/offense.rb', line 48

def disabled=(value)
  @disabled = value
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



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.message == message &&
    other.severity == severity
end

#columnObject



54
55
56
# File 'lib/erb_lint/offense.rb', line 54

def column
  source_range.column
end

#disabled?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/erb_lint/offense.rb', line 50

def disabled?
  @disabled
end

#inspectObject



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=#{message}> " \
    "severity=#{severity}"
end

#last_columnObject



66
67
68
# File 'lib/erb_lint/offense.rb', line 66

def last_column
  source_range.last_column
end

#last_lineObject



62
63
64
# File 'lib/erb_lint/offense.rb', line 62

def last_line
  source_range.last_line
end

#lengthObject



70
71
72
# File 'lib/erb_lint/offense.rb', line 70

def length
  source_range.length
end

#line_numberObject



44
45
46
# File 'lib/erb_lint/offense.rb', line 44

def line_number
  line_range.begin
end

#line_rangeObject



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_nameObject



58
59
60
# File 'lib/erb_lint/offense.rb', line 58

def simple_name
  linter.class.simple_name
end

#to_cached_offense_hashObject



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