<commit_before># encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for redundant parentheses.
      #
      # @example
      #
      #   # bad
      #   (x) if ((y.z).nil?)
      #
      #   # good
      #   x if y.z.nil?
      #
      class RedundantParentheses < Cop
        ALLOWED_LITERALS = [:irange, :erange].freeze

        def_node_matcher :method_call?, '(send _recv _msg ...)'
        def_node_matcher :square_brackets?, '(send (send _recv _msg) :[] ...)'
        def_node_matcher :range_end?, '^^{irange erange}'
        def_node_matcher :method_node_and_args, '$(send _recv _msg $...)'

        def on_begin(node)
          return unless parentheses?(node)

          child_node = node.children.first
          return offense(node, 'a literal') if disallowed_literal?(child_node)
          return offense(node, 'a variable') if child_node.variable?
          return offense(node, 'a constant') if child_node.const_type?
          return unless method_call_with_redundant_parentheses?(child_node)

          offense(node, 'a method call')
        end

        def offense(node, msg)
          add_offense(node, :expression, "Don't use parentheses around #{msg}.")
        end

        def parentheses?(node)
          node.loc.begin && node.loc.begin.is?('('.freeze)
        end

        def disallowed_literal?(node)
          node.literal? && !ALLOWED_LITERALS.include?(node.type)
        end

        def method_call_with_redundant_parentheses?(node)
          return false unless method_call?(node)
          return false if range_end?(node)

          send_node, args = method_node_and_args(node)

          send_node.loc.begin || args.empty? || square_brackets?(send_node)
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(node.loc.begin)
            corrector.remove(node.loc.end)
          end
        end
      end
    end
  end
end<commit_msg>Remove unneeded #method_call? in RedundantParentheses<commit_after># encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for redundant parentheses.
      #
      # @example
      #
      #   # bad
      #   (x) if ((y.z).nil?)
      #
      #   # good
      #   x if y.z.nil?
      #
      class RedundantParentheses < Cop
        ALLOWED_LITERALS = [:irange, :erange].freeze

        def_node_matcher :square_brackets?, '(send (send _recv _msg) :[] ...)'
        def_node_matcher :range_end?, '^^{irange erange}'
        def_node_matcher :method_node_and_args, '$(send _recv _msg $...)'

        def on_begin(node)
          return unless parentheses?(node)

          child_node = node.children.first
          return offense(node, 'a literal') if disallowed_literal?(child_node)
          return offense(node, 'a variable') if child_node.variable?
          return offense(node, 'a constant') if child_node.const_type?
          return unless method_call_with_redundant_parentheses?(child_node)

          offense(node, 'a method call')
        end

        def offense(node, msg)
          add_offense(node, :expression, "Don't use parentheses around #{msg}.")
        end

        def parentheses?(node)
          node.loc.begin && node.loc.begin.is?('('.freeze)
        end

        def disallowed_literal?(node)
          node.literal? && !ALLOWED_LITERALS.include?(node.type)
        end

        def method_call_with_redundant_parentheses?(node)
          return false unless node.send_type?
          return false if range_end?(node)

          send_node, args = method_node_and_args(node)

          send_node.loc.begin || args.empty? || square_brackets?(send_node)
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(node.loc.begin)
            corrector.remove(node.loc.end)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10383921669672765, 'fraction_numerical': 0.000515331100231899, 'mean_word_length': 2.1586655817738, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6638340', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1198, 'n_words': 266}