Sha256: 6d0509c7ce5a916d6bd35129e5233c7eb565bcfc68100b4cb33822f04f745ea9

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

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.'.freeze

        def on_method_def(_node, _method_name, args, _body)
          return unless args.loc.begin && args.loc.begin.is?('(')
          expr = args.source_range
          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

13 entries across 13 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/space_after_method_name.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.42.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.41.2 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.41.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.41.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.40.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.39.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.38.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.37.2 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.37.1 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.37.0 lib/rubocop/cop/style/space_after_method_name.rb
rubocop-0.36.0 lib/rubocop/cop/style/space_after_method_name.rb