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

Feature: add spaces_within_parenthesized_items option. #5434

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

henriquemelicias
Copy link

@henriquemelicias henriquemelicias commented Jul 9, 2022

Hello!

Tracking issue: #5435

This feature adds the option to put a space after '(' and before ')' on items surrounded by parentheses (on function/method declarations, calls, ...).

Tips on improvements would be highly appreciated!

@ytmimi
Copy link
Contributor

ytmimi commented Jul 9, 2022

Thanks for submitting your first PR 🎉

Could you open a feature request issue where we can discuss the motivation for this change as well as the scope of the new option. This PR seems focused on functions and methods, but I think there are some other areas where parentheses appear that we might also need to consider. For example, Tuple literals (a, b, c), Tuple Structs Foo()? patterns in if let if let Some(x), etc.

I also want to point out that rustfmt is an implementation of the Rust Style Guide, and there are cases like single line calls and tuple literals where this options directly goes against the prescribed behavior. rustfmt does support options that allow users to go against the style guide, but we always need to keep the style guide in mind when making these types of changes.

There's also a pending PR (#5386), which wraps certain cast expressions in parens to avoid compiler errors. I wonder if we need to hold off on this PR until after that one is merged to avoid any issues with how this option might behave with those changes.

Tips on improvements would be highly appreciated!

Default configuration tests typically live in tests/source/configs and tests/target/configs. If this is going to be a binary option we'll want to have tests for both the true and false cases.

It would also be nice to include comments in weird places to see if that affects anything.

For example, the current tests show that fn foo1() {} is left unchanged, but what happens if we add a comment and write fn foo1(/*comment*/) {}?. Do we now add spaces between the parens and the comment?


All that said, lets start with the feature request issue and take it from there.

@henriquemelicias henriquemelicias deleted the branch rust-lang:master July 9, 2022 21:28
@henriquemelicias henriquemelicias deleted the master branch July 9, 2022 21:28
@henriquemelicias henriquemelicias restored the master branch July 9, 2022 21:29
@henriquemelicias henriquemelicias deleted the master branch July 9, 2022 21:32
@henriquemelicias henriquemelicias restored the master branch July 9, 2022 21:36
@BrokenShards
Copy link

I would personally like this feature very much, partially because I write a lot of C++ and C# so I am used to having this as a formatting option in Visual Studio, but mainly because I've found that spacing brackets out can make it a lot easier to keep my place when dealing with nested parenthesis, especially with code that has a lot of nested function calls.
Any progress on the status of this PR?

@ytmimi
Copy link
Contributor

ytmimi commented Aug 1, 2023

@henriquemelicias thanks for reaching out again. This is still a fairly low-priority feature request for the team, and I don't think we'll have the bandwidth to look into this in the near future.

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.

3 participants