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
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.12.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.12.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.11.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.10.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.9.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.9.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.8.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.8.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.7.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.6.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.6.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.5.2 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.5.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-1.5.0 lib/rubocop/cop/style/symbol_literal.rb