Sha256: 8dd335933d6b94412ebc53668003b9bdc78f6fcea857a55595bbeecfd1fab53c

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

# frozen_string_literal: true

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`.'.freeze

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

          add_offense(node, :selector)
        end

        private

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.50.0 lib/rubocop/cop/style/string_methods.rb
rubocop-0.49.1 lib/rubocop/cop/style/string_methods.rb
rubocop-0.49.0 lib/rubocop/cop/style/string_methods.rb
rubocop-0.48.1 lib/rubocop/cop/style/string_methods.rb
rubocop-0.48.0 lib/rubocop/cop/style/string_methods.rb