Sha256: 4ccb039f7d9a75c85043a0dee237347555c3f7c864db7bb9d76c04090d44b1a0

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for unwanted parentheses in parameterless method calls.
      class MethodCallParentheses < Cop
        MSG = 'Do not use parentheses for method calls with no arguments.'

        def on_send(node)
          _receiver, method_name, *args = *node

          # methods starting with a capital letter should be skipped
          return if method_name =~ /\A[A-Z]/

          add_offense(node, :begin) if args.empty? && node.loc.begin
        end

        def autocorrect(node)
          # Bail out if the call is going to be auto-corrected by EmptyLiteral.
          if config.for_cop('Style/EmptyLiteral')['Enabled'] &&
              [EmptyLiteral::HASH_NODE,
               EmptyLiteral::ARRAY_NODE,
               EmptyLiteral::STR_NODE].include?(node)
            return
          end
          @corrections << lambda do |corrector|
            corrector.remove(node.loc.begin)
            corrector.remove(node.loc.end)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

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