Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Formatter] Fix space between call name and parenthesized arg #11523

Conversation

straight-shoota
Copy link
Member

When you have a call with a space between the method name and the arguments: foo (1). It is parsed as a call without parenthesis with a single arg which is itself wrapped in parenthesis.

The space is probably not intended here and the parenthesis of the argument is strictly not necessary. Most likely, this should have been written without a space as a parenthesized call.

This patch to the formatter removes that space. There should not be any semantical change because it only applies to a call with a single arg. Calls with multiple args like foo (1), 2 are not affected.

Related note: A call like foo (1, 2) is invalid syntax, so this only applies to calls that have a single argument before and after the space was removed.

This has been spotted in #11485 (comment)

@straight-shoota
Copy link
Member Author

It's actually a surprising number of instances where this change has triggered in this repo. Interestingly, the vast majority is eq calls in specs.

229d6a4 (#11523)

@HertzDevil
Copy link
Contributor

The Expressions must also have a size of 1, otherwise foo (1; 2) will be formatted to foo(1; 2), which is invalid code.

@straight-shoota straight-shoota added this to the 1.3.0 milestone Dec 6, 2021
@straight-shoota straight-shoota merged commit 6ce6604 into crystal-lang:master Dec 7, 2021
@straight-shoota straight-shoota deleted the feature/formatter-parenthesized-arg branch December 7, 2021 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants