Sha256: f2dddc221a38ed74fb9e913107c46c982b849671d8131d19d23ff8908270888a

Contents?: true

Size: 842 Bytes

Versions: 5

Compression:

Stored size: 842 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop enforces the use of consistent method names
      # from the String class.
      class StringMethods < Cop
        include MethodPreference

        MSG = 'Prefer `%s` over `%s`.'

        def on_send(node)
          _receiver, method_name, *_args = *node
          return unless preferred_methods[method_name]
          add_offense(node, :selector,
                      format(MSG,
                             preferred_method(method_name),
                             method_name)
                     )
        end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/string_methods.rb
rubocop-0.35.0 lib/rubocop/cop/style/string_methods.rb
rubocop-0.34.2 lib/rubocop/cop/style/string_methods.rb
rubocop-0.34.1 lib/rubocop/cop/style/string_methods.rb
rubocop-0.34.0 lib/rubocop/cop/style/string_methods.rb