Class: Packwerk::Offense

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/packwerk/offense.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, message:, location: nil) ⇒ Offense

Returns a new instance of Offense.



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

def initialize(file:, message:, location: nil)
  @location = location
  @file = file
  @message = message
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



15
16
17
# File 'lib/packwerk/offense.rb', line 15

def file
  @file
end

#locationObject (readonly)

Returns the value of attribute location.



12
13
14
# File 'lib/packwerk/offense.rb', line 12

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



18
19
20
# File 'lib/packwerk/offense.rb', line 18

def message
  @message
end

Instance Method Details

#to_s(style = OutputStyles::Plain.new) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/packwerk/offense.rb', line 31

def to_s(style = OutputStyles::Plain.new)
  location = self.location
  if location
    <<~EOS
      #{style.filename}#{file}#{style.reset}:#{location.line}:#{location.column}
      #{@message}
    EOS
  else
    <<~EOS
      #{style.filename}#{file}#{style.reset}
      #{@message}
    EOS
  end
end