Avoid unnecessary multiline parentheses - #42
Open
Morriar wants to merge 1 commit into
Open
Conversation
egiurleo
reviewed
Sep 2, 2026
| def correction_for(node, argument, replacement) | ||
| return replacement unless node.multiline? && node.parenthesized_call? | ||
| return replacement if argument.first_line == node.loc.begin.line && argument.last_line == node.loc.end.line | ||
| return replacement unless comments_inside_parentheses?(node) |
There was a problem hiding this comment.
I believe this will fail the following case:
value = (
<<~TEXT
hello
TEXT
).not_nil!
by converting it to value = <<~TEXT.not_nil!
argument.source is just the <<~TEXT portion of the heredoc so returning the replacement in this case truncates the rest of the heredoc. Probably worth adding a test?
Contributor
Author
There was a problem hiding this comment.
Good catch, I added a special case for heredoc. I decided to preserve the parenthesis around it to avoid messing with indentation.
So this:
foo = T.must(
<<~FOO
hello
FOO
)becomes this:
foo = (
<<~FOO
hello
FOO
).not_nil!instead of this:
foo = <<~FOO.not_nil!
hello
FOO
Base automatically changed from
fix/prefer-not-nil-block-parentheses
to
fix/prefer-not-nil-multiline-receiver
September 9, 2026 17:50
Morriar
force-pushed
the
fix/prefer-not-nil-multiline-receiver
branch
from
September 9, 2026 17:59
4a89554 to
55210f9
Compare
Base automatically changed from
fix/prefer-not-nil-multiline-receiver
to
main
September 9, 2026 18:00
Morriar
force-pushed
the
fix/prefer-not-nil-multiline-parentheses
branch
from
September 9, 2026 18:10
94e64e5 to
bc05c0b
Compare
Morriar
force-pushed
the
fix/prefer-not-nil-multiline-parentheses
branch
from
September 9, 2026 18:49
552e922 to
4a85d32
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Avoid unnecessary parentheses when autocorrecting multiline
T.mustcalls without comments.Before:
After:
Calls containing comments keep the grouped form so comments and internal indentation are preserved.