Sha256: 6ac402299e03c4cbcc9c19eac55510c1e82f4294ea2c46d107a9e0480500b377

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

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

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

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

      # @api private
      def to_s
        @name.to_s
      end

      # @api private
      def code
        @name.to_s[0].upcase
      end

      # @api private
      def level
        NAMES.index(name) + 1
      end

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

      # @api private
      def hash
        @name.hash
      end

      # @api private
      def <=>(other)
        level <=> other.level
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
rubocop-0.89.1 lib/rubocop/cop/severity.rb
rubocop-0.89.0 lib/rubocop/cop/severity.rb
rubocop-0.88.0 lib/rubocop/cop/severity.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/severity.rb
rubocop-0.87.1 lib/rubocop/cop/severity.rb
rubocop-0.87.0 lib/rubocop/cop/severity.rb
rubocop-0.86.0 lib/rubocop/cop/severity.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/severity.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/severity.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/severity.rb
rubocop-0.85.1 lib/rubocop/cop/severity.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/severity.rb
rubocop-0.85.0 lib/rubocop/cop/severity.rb
rubocop-0.84.0 lib/rubocop/cop/severity.rb