Class: RuboCop::Cop::Offense
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
Comparable
|
|
| Inherits: | Object |
| Defined in: | lib/rubocop/cop/offense.rb |
Overview
An offense represents a style violation detected by RuboCop.
Constant Summary
-
COMPARISON_ATTRIBUTES =
Internal use only
# File 'lib/rubocop/cop/offense.rb', line 10%i[line column cop_name message severity].freeze
-
NO_LOCATION =
# File 'lib/rubocop/cop/offense.rb', line 87PseudoSourceRange.new(1, 0, '', 0, 0).freeze
Class Method Summary
- .new(severity, location, message, cop_name, status = :uncorrected, corrector = nil) ⇒ Offense constructor Internal use only Internal use only
Instance Attribute Summary
- #cop_name ⇒ String readonly
- #correctable? ⇒ Boolean readonly
- #corrected? ⇒ Boolean readonly
- #corrected_with_todo? ⇒ Boolean readonly
- #corrector ⇒ Corrector | nil readonly
- #disabled? ⇒ Boolean readonly
- #location ⇒ Parser::Source::Range readonly
- #message ⇒ String readonly
- #severity ⇒ RuboCop::Cop::Severity readonly
- #status readonly Internal use only Internal use only
Instance Method Summary
-
#<=>(other) ⇒ Integer
Returns
-1,0, or+1if this offense is less than, equal to, or greater thanother. - #==(other) ⇒ Boolean (also: #eql?)
- #column Internal use only Internal use only
- #column_length Internal use only Internal use only
- #column_range Internal use only Internal use only
-
#eql?(other)
Alias for #==.
- #first_line Internal use only Internal use only
- #hash
- #highlighted_area ⇒ Parser::Source::Range
- #last_column Internal use only Internal use only
- #last_line Internal use only Internal use only
- #line Internal use only Internal use only
- #marshal_dump
- #marshal_load(array)
-
#real_column
Internal use only
Internal use only
Internally we use column number that start at 0, but when outputting column numbers, we want them to start at 1.
- #source_line Internal use only Internal use only
-
#to_s
Internal use only
Internal use only
This is just for debugging purpose.
Instance Attribute Details
#cop_name ⇒ String (readonly)
# File 'lib/rubocop/cop/offense.rb', line 50
attr_reader :cop_name
#correctable? ⇒ Boolean (readonly)
# File 'lib/rubocop/cop/offense.rb', line 116
def correctable? @status != :unsupported end
#corrected? ⇒ Boolean (readonly)
# File 'lib/rubocop/cop/offense.rb', line 127
def corrected? @status == :corrected || @status == :corrected_with_todo end
#corrected_with_todo? ⇒ Boolean (readonly)
# File 'lib/rubocop/cop/offense.rb', line 137
def corrected_with_todo? @status == :corrected_with_todo end
#corrector ⇒ Corrector | nil (readonly)
# File 'lib/rubocop/cop/offense.rb', line 61
attr_reader :corrector
#disabled? ⇒ Boolean (readonly)
# File 'lib/rubocop/cop/offense.rb', line 148
def disabled? @status == :disabled || @status == :todo end
#location ⇒ Parser::Source::Range (readonly)
# File 'lib/rubocop/cop/offense.rb', line 28
attr_reader :location
#message ⇒ String (readonly)
# File 'lib/rubocop/cop/offense.rb', line 39
attr_reader :
#severity ⇒ RuboCop::Cop::Severity (readonly)
# File 'lib/rubocop/cop/offense.rb', line 17
attr_reader :severity
#status (readonly)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 53
attr_reader :status
Instance Method Details
#<=>(other) ⇒ Integer
Returns -1, 0, or +1
if this offense is less than, equal to, or greater than other.
# File 'lib/rubocop/cop/offense.rb', line 245
def <=>(other) COMPARISON_ATTRIBUTES.each do |attribute| result = public_send(attribute) <=> other.public_send(attribute) return result unless result.zero? end 0 end
#==(other) ⇒ Boolean
Also known as: #eql?
# File 'lib/rubocop/cop/offense.rb', line 226
def ==(other) COMPARISON_ATTRIBUTES.all? do |attribute| public_send(attribute) == other.public_send(attribute) end end
#column
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 175
def column location.column end
#column_length
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 185
def column_length if first_line == last_line column_range.count else source_line.length - column end end
#column_range
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 209
def column_range location.column_range end
#eql?(other)
Alias for #==.
# File 'lib/rubocop/cop/offense.rb', line 232
alias eql? ==
#first_line
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 194
def first_line location.first_line end
#hash
[ GitHub ]# File 'lib/rubocop/cop/offense.rb', line 234
def hash COMPARISON_ATTRIBUTES.map { |attribute| public_send(attribute) }.hash end
#highlighted_area ⇒ Parser::Source::Range
# File 'lib/rubocop/cop/offense.rb', line 156
def highlighted_area source_buffer = Parser::Source::Buffer.new(location.source_buffer.name, source: source_line) Parser::Source::Range.new(source_buffer, column, column + column_length) end
#last_column
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 204
def last_column location.last_column end
#last_line
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 199
def last_line location.last_line end
#line
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 170
def line location.line end
#marshal_dump
[ GitHub ]# File 'lib/rubocop/cop/offense.rb', line 101
def marshal_dump [@severity, @location, @message, @cop_name, @status] end
#marshal_load(array)
[ GitHub ]# File 'lib/rubocop/cop/offense.rb', line 105
def marshal_load(array) @severity, @location, @message, @cop_name, @status = array end
#real_column
This method is for internal use only.
Internally we use column number that start at 0, but when outputting column numbers, we want them to start at 1. One reason is that editors, such as Emacs, expect this.
# File 'lib/rubocop/cop/offense.rb', line 218
def real_column column + 1 end
#source_line
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/cop/offense.rb', line 180
def source_line location.source_line end
#to_s
This method is for internal use only.
This is just for debugging purpose.
# File 'lib/rubocop/cop/offense.rb', line 163
def to_s format('%<severity>s:%3<line>d:%3<column>d: %<message>s', severity: severity.code, line: line, column: real_column, message: ) end