Sha256: 91de646be67479ee3e68dfd21f4d461809f758b36c4be702832d398fac2c5daa

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 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.'.freeze

        def on_def(node)
          args = node.arguments
          return unless args.loc.begin && 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 =~ /\s/

          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

11 entries across 11 versions & 2 rubygems

Version Path
rubocop-0.58.2 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.58.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.58.0 lib/rubocop/cop/layout/space_after_method_name.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.57.2 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.57.1 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.57.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.56.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.55.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.54.0 lib/rubocop/cop/layout/space_after_method_name.rb
rubocop-0.53.0 lib/rubocop/cop/layout/space_after_method_name.rb