Sha256: fc1038a2da6181b8e390e5709a46df910b7b42123ec9798ea434ccdd666e8d8f

Contents?: true

Size: 931 Bytes

Versions: 12

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # 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 < Base
        include MethodPreference
        extend AutoCorrector

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

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

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

          add_offense(node.loc.selector, message: message) do |corrector|
            corrector.replace(node.loc.selector, preferred_method(node.method_name))
          end
        end
        alias on_csend on_send
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
rubocop-1.74.0 lib/rubocop/cop/style/string_methods.rb
rubocop-1.73.2 lib/rubocop/cop/style/string_methods.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/cop/style/string_methods.rb
rubocop-1.73.1 lib/rubocop/cop/style/string_methods.rb
rubocop-1.73.0 lib/rubocop/cop/style/string_methods.rb
rubocop-1.72.2 lib/rubocop/cop/style/string_methods.rb
rubocop-1.72.1 lib/rubocop/cop/style/string_methods.rb
rubocop-1.72.0 lib/rubocop/cop/style/string_methods.rb
rubocop-1.71.2 lib/rubocop/cop/style/string_methods.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/style/string_methods.rb
rubocop-1.71.1 lib/rubocop/cop/style/string_methods.rb
rubocop-1.71.0 lib/rubocop/cop/style/string_methods.rb