123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::Severity

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Comparable
Inherits: Object
Defined in: lib/rubocop/cop/severity.rb

Overview

Severity class is simple value object about severity

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name_or_code) ⇒ Severity

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 42

def initialize(name_or_code)
  name = Severity.name_from_code(name_or_code)
  raise ArgumentError, "Unknown severity: #{name}" unless NAMES.include?(name)

  @name = name.freeze
  freeze
end

Class Method Details

.minimum_to_fail(options, config)

The lowest severity that makes a run fail: --fail-level when given, otherwise AllCops: FailLevel. autocorrect is a pseudo level on the command line that gates on corrections instead, so it leaves the threshold at the configured one.

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 28

def self.minimum_to_fail(options, config)
  name = options[:fail_level]
  if name.nil? || name == :autocorrect
    name = (config&.for_all_cops&.[]('FailLevel') || :refactor).to_sym
  end
  new(name)
end

.name_from_code(code)

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 36

def self.name_from_code(code)
  name = code.to_sym
  CODE_TABLE[name] || name
end

Instance Attribute Details

#nameSymbol (readonly)

Returns:

  • (Symbol)

    severity. any of :info, :refactor, :convention, :warning, :error or :fatal.

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 22

attr_reader :name

Instance Method Details

#<=>(other)

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 74

def <=>(other)
  level <=> other.level
end

#==(other)

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 62

def ==(other)
  @name == if other.is_a?(Symbol)
             other
           else
             other.name
           end
end

#code

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 54

def code
  @name.to_s[0].upcase
end

#hash

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 70

def hash
  @name.hash
end

#level

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 58

def level
  NAMES.index(name) + 1
end

#to_s

[ GitHub ]

  
# File 'lib/rubocop/cop/severity.rb', line 50

def to_s
  @name.to_s
end