Skip to content

parentheses-as-grouped-expression

Rubysuspiciousno fixdefault: offruby/rubocop

Reports a space between a method name and a ( that holds its only argument (puts (x)). A call whose argument goes on after the parentheses (puts (1 + 2) * 3) is not reported.

Ruby reads the parentheses as grouping the argument, not as enclosing the arguments of the call. With one argument the result is the same, but the form changes meaning when the code is edited: puts (1 + 2).abs calls abs on the group inside the call, while puts(1 + 2).abs calls it on the result of puts.

To fix, remove the space before (.

Reported
...
raise StandardError
foo (1)
foo (a ? b : c)
foo(1)
...
ruby:
lint:
rules:
parentheses-as-grouped-expression: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line parentheses-as-grouped-expression in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/ParenthesesAsGroupedExpression full