Sha256: a1b23f55794791d2e8580c1322fba9bc43f6dfbdcab9150291af1813a31eeb07

Contents?: true

Size: 1.11 KB

Versions: 62

Compression:

Stored size: 1.11 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 < Cop
        include RangeHelp

        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, location: pos_before_left_paren)
        end
        alias on_defs on_def

        def autocorrect(pos_before_left_paren)
          ->(corrector) { corrector.remove(pos_before_left_paren) }
        end
      end
    end
  end
end

Version data entries

62 entries across 43 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.89.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.89.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.88.0 lib/rubocop/cop/layout/space_after_method_name.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.87.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.87.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.86.0 lib/rubocop/cop/layout/space_after_method_name.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/layout/space_after_method_name.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/layout/space_after_method_name.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.85.1 lib/rubocop/cop/layout/space_after_method_name.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.85.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.84.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.83.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.82.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.81.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.80.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.80.0 lib/rubocop/cop/layout/space_after_method_name.rb