You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are using parentheses, Ruby let's you place the question mark operator of a ternary like this:
(foo)? bar : baz
(Note the lack of space between the condition and the operator.)
Style/TernaryParentheses needs to keep this in mind when auto-correcting, as currently it will generate invalid Ruby code by just removing the closing paren.
(This offense is separately checked by Style/SpaceAroundOperators, but we can't count on it being always enabled and first.)
Expected behavior
RuboCop should auto-correct to:
foo ? bar : baz
Actual behavior
RuboCop auto-corrects to:
foo? ? bar : baz
Steps to reproduce the problem
Run bundle exec rubocop --only Style/TernaryParentheses -a on:
(foo)? bar : baz
RuboCop version
Include the output of rubocop -V. Here's an example:
The space between ternary condition and question mark is not required if
the condition is parenthesized. Auto-correct would remove the
parentheses and generate invalid Ruby code.
```ruby
(foo)? bar : baz # valid Ruby code
foo? bar : baz # invalid auto-correct before
foo ? bar : baz # after the fix
```
If you are using parentheses, Ruby let's you place the question mark operator of a ternary like this:
(Note the lack of space between the condition and the operator.)
Style/TernaryParentheses
needs to keep this in mind when auto-correcting, as currently it will generate invalid Ruby code by just removing the closing paren.(This offense is separately checked by
Style/SpaceAroundOperators
, but we can't count on it being always enabled and first.)Expected behavior
RuboCop should auto-correct to:
Actual behavior
RuboCop auto-corrects to:
Steps to reproduce the problem
Run
bundle exec rubocop --only Style/TernaryParentheses -a
on:RuboCop version
Include the output of
rubocop -V
. Here's an example:The text was updated successfully, but these errors were encountered: