Sha256: 2cf955b673459797bf105c01a6863253a9070cbe3e59604cf8799e65124e56cf

Contents?: true

Size: 661 Bytes

Versions: 46

Compression:

Stored size: 661 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 < Cop
        MSG = 'Do not use strings for word-like symbol literals.'

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

          add_offense(node)
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node.source_range, node.source.delete(%q('")))
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 27 versions & 3 rubygems

Version Path
rubocop-0.76.0 lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.75.1 lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.75.0 lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/style/symbol_literal.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.74.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.73.0 lib/rubocop/cop/style/symbol_literal.rb