class RuboCop::Cop::Style::MethodCallWithArgsParentheses
Array 1
# good
Array(1)
# good
@example AllowParenthesesInCamelCaseMethod: true
Array 1
# good
Array(1)
# bad
@example AllowParenthesesInCamelCaseMethod: false (default)
foo().bar 1
# good
foo().bar(1)
# good
@example AllowParenthesesInChaining: true
foo().bar 1
# good
foo().bar(1)
# bad
@example AllowParenthesesInChaining: false (default)
strict: true
foo.enforce <br># good
)
strict: true
foo.enforce(
# good
@example AllowParenthesesInMultilineCall: true
strict: true
foo.enforce <br># good
)
strict: true
foo.enforce(
# bad
@example AllowParenthesesInMultilineCall: false (default)
end
bar :baz
class Foo
# bad
@example IgnoreMacros: false
end
bar :baz
class Foo
# good
@example IgnoreMacros: true (default)
foo.enforce strict: true
# good
foo.enforce(strict: true)
# bad
array.delete e
# good
array.delete(e)
# bad
@example EnforcedStyle: omit_parentheses
assert_equal ‘test’, x
# okay with ‘^assert` listed in `IgnoredPatterns`
puts ’test’
# okay with ‘puts` listed in `IgnoredMethods`
foo.bar = baz
# Setter methods don’t need parens
# good
foo == bar
# Operators don’t need parens
# good
array.delete(e)
# good
array.delete e
# bad
@example EnforcedStyle: require_parentheses (default)
even with arguments.
to ‘true` allows the presence of parentheses in such a method call
begins with a capital letter and which has no arguments. Setting it
allows the presence of parentheses when calling a method whose name
3. `AllowParenthesesInCamelCaseMethod` is `false` by default. This
calls.
to `true` allows the presence of parentheses in multi-line method
2. `AllowParenthesesInMultilineCall` is `false` by default. Setting it
method chaining.
`true` allows the presence of parentheses in the last call during
1. `AllowParenthesesInChaining` is `false` by default. Setting it to
options.
In the alternative style (omit_parentheses), there are three additional
precedence (that is, the method is ignored).
`IncludedMacros` and `IgnoredMethods`, then the latter takes
eg. If a method is listed in both
3. `IncludedMacros`
2. `IgnoredPatterns`
1. `IgnoredMethods`
Precedence of options is all follows:
the `IncludedMacros` list.
either setting `IgnoreMacros` to false or adding specific macros to
valid only in the default style. Macros can be included by
or `IgnoredPatterns` list. These options are
Additional methods can be added to the `IgnoredMethods`
In the default style (require_parentheses), macro methods are ignored.
method calls containing parameters.
This cop enforces the presence (default) or absence of parentheses in
def args_begin(node)
def args_begin(node) loc = node.loc selector = node.super_type? || node.yield_type? ? loc.keyword : loc.selector resize_by = args_parenthesized?(node) ? 2 : 1 selector.end.resize(resize_by) end
def args_end(node)
def args_end(node) node.loc.expression.end end
def args_parenthesized?(node)
def args_parenthesized?(node) return false unless node.arguments.one? first_node = node.arguments.first first_node.begin_type? && first_node.parenthesized_call? end
def on_send(node)
def on_send(node) send(style, node) # call require_parentheses or omit_parentheses end