<commit_before># 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
<commit_msg>Replace regular expression usage in SpaceAfterMethodName cop<commit_after># 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.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

{'fraction_non_alphanumeric': 0.071843853820598, 'fraction_numerical': 0.0008305647840531562, 'mean_word_length': 1.7689655172413794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '248092', 'n_tokens_mistral': 715, 'n_tokens_neox': 709, 'n_words': 189}