Sha256: 157ee6388b24d4090d0a236a971279a095622facb26df6af616f30aec8b4c8a3

Contents?: true

Size: 1017 Bytes

Versions: 228

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # Checks for space between a method name and a left parenthesis in defs.
      #
      # @example
      #
      #   # bad
      #   def func (x) end
      #   def method= (y) end
      #
      #   # good
      #   def func(x) end
      #   def method=(y) end
      class SpaceAfterMethodName < Base
        include RangeHelp
        extend AutoCorrector

        MSG = 'Do not put a space between a method name and the opening parenthesis.'

        def on_def(node)
          args = node.arguments
          return unless args.loc.begin&.is?('(')

          expr = args.source_range
          pos_before_left_paren = range_between(expr.begin_pos - 1, expr.begin_pos)
          return unless pos_before_left_paren.source.start_with?(' ')

          add_offense(pos_before_left_paren) do |corrector|
            corrector.remove(pos_before_left_paren)
          end
        end
        alias on_defs on_def
      end
    end
  end
end

Version data entries

228 entries across 219 versions & 22 rubygems

Version Path
rubocop-1.63.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.63.0 lib/rubocop/cop/layout/space_after_method_name.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.62.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.62.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.61.0 lib/rubocop/cop/layout/space_after_method_name.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.60.2 lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.60.1 lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.60.0 lib/rubocop/cop/layout/space_after_method_name.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/space_after_method_name.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/space_after_method_name.rb