Sha256: 4e3f4fd8ee2062c802f8ea5cc3137d8956dd5691141bcc3f0877f3c65988d8bb

Contents?: true

Size: 624 Bytes

Versions: 35

Compression:

Stored size: 624 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks symbol literal syntax.
      #
      # @example
      #
      #   # bad
      #   :"symbol"
      #
      #   # good
      #   :symbol
      class SymbolLiteral < Base
        extend AutoCorrector

        MSG = 'Do not use strings for word-like symbol literals.'

        def on_sym(node)
          return unless /\A:["'][A-Za-z_]\w*["']\z/.match?(node.source)

          add_offense(node) do |corrector|
            corrector.replace(node, node.source.delete(%q('")))
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
rubocop-1.4.2 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.4.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.4.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.3.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.3.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.2.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.1.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.0.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.93.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.93.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.92.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.91.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.91.0 lib/rubocop/cop/style/symbol_literal.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.90.0/lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.90.0 lib/rubocop/cop/style/symbol_literal.rb