-
Notifications
You must be signed in to change notification settings - Fork 927
Configuration option to preserve blank lines at start of block #4303
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
Conversation
(don't let the 900 line diff scare you; ~800 of it is tests) |
That made me chuckle, as my eyes did pop at first before I saw that note 👀 |
I know the original issue only referenced start of blocks, but I have a suspicion that a decent size chunk of users that would leverage this config option may also be interested in something similar for the end of blocks. Do you think an equivalent end-of-block config and behavior would be feasible, and if so would it make sense for those to be two distinct config options or easier to use as one? Based on the explanation in the linked issue it sounds like there's scenarios where folks may want to keep the lines at the beginning but still trim at the end so separate would probably be best for more granular control. |
That makes sense to me, if people want one they may want the other. I definitely think it's feasible (and probably easily doable, but those are famous last words). However I also think it's worth waiting and seeing if there are any requests for such a configuration option, as it's easier to add an option than remove one (from a stability and "how many people are using this?" point of view). What do you think? |
This is totally orthogonal, but it would be interesting to pull GitHub data and see what are the most common rustfmt options are too. |
Agreed, and certainly no need to do anything with end of block lines as part of this PR, I'm betting it'll get requested sooner or later though.
Definitely! Funny you should mention this, as just the other day I was thinking about how beneficial it would be to have quantitative data about config option usage. There's some that we know are used pretty extensively in their respective corners ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, thank you so much! I've left a few thoughts/questions inline for your review, but since this is adding a new config option I'll defer to @topecongiro for approval and merging
Thanks for the updates! I'll try to get back to this soon, though have also requested a review from @topecongiro for the reasons mentioned earlier in the thread. One of the things that I can't quite shake is a feeling that there's a little too much going on with For example, I can see 3 different branches internal to the function that can all result in function returning the exact same thing, an empty string, and the length of the returned string (or more precisely whether or not it's empty) is significant for at least some consumers. I don't have any specific suggestions/modifications just yet (although maybe wrapping the return string in an Option could help?) and I wouldn't say this is a blocking concern for me; just wanted to share my thinking. Properly (and idempotently) maintaining line spacing is certainly a nontrivial task and you've done a great job here! |
I tried to condense the logic a bit, lmk what you think |
https://github.com/rust-lang/rustfmt/pull/4295/files broke this, so there is probably a better way to handle this using the code there... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayazhafiz @calebcartwright Thank you forks! The PR LGTM, and additional thanks for writing more tests ❤️
Adds the option for - Functions - Control flow blocks - Expression statements (i.e. `let x = { ... };`) - Traits - Trait Impls - Mods - Foreign Mods If I am missing a kind of item, let me know :) Closes rust-lang#2868
Thanks for the changes @ayazhafiz! I know it was fairly minor but I definitely appreciate the updated |
…lang#4303) * Configuration option to preserve blank lines at start of block Adds the option for - Functions - Control flow blocks - Expression statements (i.e. `let x = { ... };`) - Traits - Trait Impls - Mods - Foreign Mods If I am missing a kind of item, let me know :) Closes rust-lang#2868 * fixup! Configuration option to preserve blank lines at start of block * Simplify `advance_to_first_block_item` * fixup! Simplify `advance_to_first_block_item`
Adds the option for
let x = { ... };
)If I am missing a kind of item, let me know :)
Closes #2868