Fix incorrect shorthand autocorrections in calls inside parentheses #11643
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you happen to have a method call without parentheses that is inside outer parentheses like the following example:
We would have still thought that we need to add parentheses to the
create
call duringStyle/HashSyntax
autocorrection like so:While this is not a problem in isolation, it can lead to invalid Ruby autocorrections when
Style/HashSyntax
is used in combination withStyle/RedundantParentheses
(enabled by default) andStyle/MethodCallWithArgsParentheses
(disabled by default) withEnforcedStyle: omit_parentheses
:I have two problematic examples:
1.
Autocorrects to broken Ruby like so:
This happens because
Style/HashSyntax
puts parentheses in(create(:integration_shop, account:))
, which then gets autocorrected byStyle/MethodCallWithArgsParentheses
to(create :integration_shop, account:)
that finally gets processed byStyle/RedundantParentheses
tocreate :integration_shop, account:
.2.
Gets autocorrected to:
The reason is the same, the unforunate play between
Style/HashSyntax
,Style/MethodsAcceptingSymbol
withEnforcedStyle: omit_parentheses
andStyle/RedundantParentheses
.An fix is not to parenthesize the calls with value omission if they are inside parentheses. That's one of the drawbacks of omitting parentheses, sometimes folks decide to put them in funny places like around a method call.