Sha256: ba67bda03e0afa55d4250d1af79250a59e6529574c536c69c62df214aa070d64

Contents?: true

Size: 1.05 KB

Versions: 6765

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop enforces the use of consistent method names
      # from the String class.
      #
      # @example
      #   # bad
      #   'name'.intern
      #   'var'.unfavored_method
      #
      #   # good
      #   'name'.to_sym
      #   'var'.preferred_method
      class StringMethods < Cop
        include MethodPreference

        MSG = 'Prefer `%<prefer>s` over `%<current>s`.'.freeze

        def on_send(node)
          return unless preferred_method(node.method_name)

          add_offense(node, location: :selector)
        end
        alias on_csend on_send

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node.loc.selector,
                              preferred_method(node.method_name))
          end
        end

        private

        def message(node)
          format(MSG,
                 prefer: preferred_method(node.method_name),
                 current: node.method_name)
        end
      end
    end
  end
end

Version data entries

6,765 entries across 6,761 versions & 23 rubygems

Version Path
cybrid_api_organization_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_organization_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_organization_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_organization_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_organization_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_organization_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_bank_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb
cybrid_api_id_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/string_methods.rb