Sha256: ca3dcbdb73f93864826a0801769744db502259fcf6bfaa164680e6b6f04a4820

Contents?: true

Size: 668 Bytes

Versions: 6793

Compression:

Stored size: 668 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.'.freeze

        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

6,793 entries across 6,787 versions & 25 rubygems

Version Path
rubocop-0.58.0 lib/rubocop/cop/style/symbol_literal.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.57.2 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.57.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.57.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.56.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.55.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.54.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.53.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.52.1 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.52.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.51.0 lib/rubocop/cop/style/symbol_literal.rb
rubocop-0.50.0 lib/rubocop/cop/style/symbol_literal.rb