Sha256: 607226db061f5f6be55a0b98fcad10d325753659142b37330637194ddb451eee

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 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 OnMethod

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

        def on_method(_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)
          @corrections << lambda do |corrector|
            corrector.remove(pos_before_left_paren)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_method_name.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.26.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.26.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.25.0 lib/rubocop/cop/style/space_after_method_name.rb