Class: Packwerk::Offense

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

: (file: String, message: String, ?location: Node::Location?) -> void



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

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

Instance Attribute Details

#fileObject (readonly)

: String



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

def file
  @file
end

#locationObject (readonly)

: Node::Location?



9
10
11
# File 'lib/packwerk/offense.rb', line 9

def location
  @location
end

#messageObject (readonly)

: String



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

def message
  @message
end

Instance Method Details

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

: (?OutputStyle style) -> String



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/packwerk/offense.rb', line 25

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