class RuboCop::Cop::Style::MethodCallWithArgsParentheses
This cop checks presence of parentheses in method calls containing parameters. By default, macro methods are ignored. Additional methods can be added to the `IgnoredMethods` list.
@example
# bad array.delete e # good array.delete(e) # good # Operators don't need parens foo == bar # good # Setter methods don't need parens foo.bar = baz # okay with `puts` listed in `IgnoredMethods` puts 'test' # IgnoreMacros: true (default) # good class Foo bar :baz end # IgnoreMacros: false # bad class Foo bar :baz end
Constants
- MSG
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 45 def on_send(node) return if ignored_method?(node) return unless node.arguments? && !node.parenthesized? add_offense(node) end
Private Instance Methods
args_begin(node)
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 77 def args_begin(node) loc = node.loc selector = node.super_type? || node.yield_type? ? loc.keyword : loc.selector selector.end.resize(1) end
args_end(node)
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 84 def args_end(node) node.loc.expression.end end
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 56 def autocorrect(node) lambda do |corrector| corrector.replace(args_begin(node), '(') corrector.insert_after(args_end(node), ')') end end
ignore_macros?()
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 73 def ignore_macros? cop_config['IgnoreMacros'] end
ignored_list()
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 69 def ignored_list cop_config['IgnoredMethods'].map(&:to_sym) end
ignored_method?(node)
click to toggle source
# File lib/rubocop/cop/style/method_call_with_args_parentheses.rb, line 63 def ignored_method?(node) node.operator_method? || node.setter_method? || ignore_macros? && node.macro? || ignored_list.include?(node.method_name) end