Sha256: a30713576d66a05aab2eb026a8c1e52b0def815a7bd101a6a64efe8c4d5cd72e

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Severity class is simple value object about severity
    class Severity
      include Comparable

      NAMES = %i[refactor convention warning error fatal].freeze

      # @api private
      CODE_TABLE = { R: :refactor, C: :convention,
                     W: :warning, E: :error, F: :fatal }.freeze

      # @api public
      #
      # @!attribute [r] name
      #
      # @return [Symbol]
      #   severity.
      #   any of `:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
      attr_reader :name

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

      # @api private
      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

      def to_s
        @name.to_s
      end

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

      def level
        NAMES.index(name) + 1
      end

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

      def hash
        @name.hash
      end

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

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/severity.rb
rubocop-1.8.1 lib/rubocop/cop/severity.rb
rubocop-1.8.0 lib/rubocop/cop/severity.rb
rubocop-1.7.0 lib/rubocop/cop/severity.rb
rubocop-1.6.1 lib/rubocop/cop/severity.rb
rubocop-1.6.0 lib/rubocop/cop/severity.rb
rubocop-1.5.2 lib/rubocop/cop/severity.rb
rubocop-1.5.1 lib/rubocop/cop/severity.rb
rubocop-1.5.0 lib/rubocop/cop/severity.rb
rubocop-1.4.2 lib/rubocop/cop/severity.rb
rubocop-1.4.1 lib/rubocop/cop/severity.rb
rubocop-1.4.0 lib/rubocop/cop/severity.rb
rubocop-1.3.1 lib/rubocop/cop/severity.rb
rubocop-1.3.0 lib/rubocop/cop/severity.rb
rubocop-1.2.0 lib/rubocop/cop/severity.rb