Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Offense

An offense represents a style violation detected by RuboCop.

Attributes

column[R]

@api private

cop_name[R]

@api public

@!attribute [r] cop_name

@return [String]

a cop class name without namespace.
i.e. type of the violation.

@example

'LineLength'
corrected[R]

@api public

@!attribute [r] corrected

@return [Boolean]

whether this offense is automatically corrected.
corrected?[R]

@api public

@!attribute [r] corrected

@return [Boolean]

whether this offense is automatically corrected.
line[R]

@api private

location[R]

@api public

@!attribute [r] location

@return [Parser::Source::Range]

the location where the violation is detected.

@see rubydoc.info/github/whitequark/parser/Parser/Source/Range

Parser::Source::Range
message[R]

@api public

@!attribute [r] message

@return [String]

human-readable message

@example

'Line is too long. [90/80]'
severity[R]

@api public

@!attribute [r] severity

@return [RuboCop::Cop::Severity]

Public Class Methods

new(severity, location, message, cop_name, corrected = false) click to toggle source

@api private

# File lib/rubocop/cop/offense.rb, line 65
def initialize(severity, location, message, cop_name, corrected = false)
  @severity = RuboCop::Cop::Severity.new(severity)
  @location = location.freeze
  @line = location.line.freeze
  @column = location.column.freeze
  @message = message.freeze
  @cop_name = cop_name.freeze
  @corrected = corrected.freeze
  freeze
end

Public Instance Methods

<=>(other) click to toggle source

@api public

Returns `-1`, `0` or `+1` if this offense is less than, equal to, or greater than `other`.

@return [Integer]

comparison result
# File lib/rubocop/cop/offense.rb, line 109
def <=>(other)
  [:line, :column, :cop_name, :message].each do |attribute|
    result = send(attribute) <=> other.send(attribute)
    return result unless result == 0
  end
  0
end
==(other) click to toggle source

@api public

@return [Boolean]

returns `true` if two offenses contain same attributes
# File lib/rubocop/cop/offense.rb, line 96
def ==(other)
  severity == other.severity && line == other.line &&
    column == other.column && message == other.message &&
    cop_name == other.cop_name
end
real_column() click to toggle source

@api private

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 88
def real_column
  column + 1
end
to_s() click to toggle source

@api private This is just for debugging purpose.

# File lib/rubocop/cop/offense.rb, line 78
def to_s
  format('%s:%3d:%3d: %s',
         severity.code, line, real_column, message)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.