Sha256: cf61058f06c9e9efeb452210a12a0dd56d77e841d8c61a3ab8945397d0e4d19d

Contents?: true

Size: 1.06 KB

Versions: 35

Compression:

Stored size: 1.06 KB

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

35 entries across 35 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.12.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.12.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.11.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.10.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.9.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.9.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.8.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.8.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.7.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.6.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.6.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.5.2 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.5.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-1.5.0 lib/rubocop/cop/layout/space_after_method_name.rb