Sha256: ea7f5ea032ad069eaa6e0efe2ae150bdd2ffd29f3d2f19c2b5444cb97fe55f51

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # Checks for space between a method name and a left parenthesis in defs.
      #
      # @example
      #
      #   # bad
      #   def func (x) ... end
      #
      #   # good
      #   def func(x) ... end
      class SpaceAfterMethodName < Cop
        include OnMethodDef

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

        def on_method_def(_node, _method_name, args, _body)
          return unless args.loc.begin && args.loc.begin.is?('(')
          expr = args.loc.expression
          pos_before_left_paren = Parser::Source::Range.new(expr.source_buffer,
                                                            expr.begin_pos - 1,
                                                            expr.begin_pos)
          return unless pos_before_left_paren.source =~ /\s/

          add_offense(pos_before_left_paren, pos_before_left_paren)
        end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.35.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.34.2 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.34.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.34.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.33.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.32.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.32.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.31.0 lib/rubocop/cop/style/space_after_method_name.rb