-
Notifications
You must be signed in to change notification settings - Fork 892
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
Add config option generated_file_header_size
#5659
Add config option generated_file_header_size
#5659
Conversation
I wonder if it would be preferable to make |
@captbaritone thanks for your first contribution to rustfmt 🎉 The tests are failing because we're missing an entry in Configurations.md for the new config option. additionally it would be nice to include some tests to validate the behavior of the new option.
Interesting idea! Are you suggesting the configuration should be something like this:
|
Upon further consideration the Let me know if you can come up with anything better than the current approach of |
…nes to look at when checking for @generated
673535f
to
a493f31
Compare
|
||
- **Default value**: `5` | ||
- **Possible values**: any positive integer | ||
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080)) |
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.
Should these two config options be promoted to stable together? Or should I create a new issue to track promoting this option?
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.
I think it's would be fine to stabilize these at the same time.
@ytmimi I've added documentation and tests. |
Hey, @ytmimi just following up to see if there's any feedback on this. |
By default, generated files are reformatted, i. e. `@generated` marker is ignored. | ||
This option is currently ignored for stdin (`@generated` in stdin is ignored.) | ||
|
||
- **Default value**: `true` | ||
- **Possible values**: `true`, `false` | ||
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080)) | ||
|
||
## `generated_file_header_size` | ||
|
||
Number of lines to check for a `@generated` pragma header when `format_generated_files` is enabled. When `format_generated_files` is disabled, this option has no effect. |
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.
Let's reword this to be clearer about when this option has an effect:
Number of lines to check for a @generated
pragma header when format_generated_files
is false. When format_generated_files
is true, this option has no effect.
- **Default value**: `5` | ||
- **Possible values**: any positive integer | ||
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080)) | ||
|
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.
Lets add a See also [
format_generated_files](#format_generated_files)
link here.
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.
Thanks for your work on this!
The implementation looks good, I'd just want us to make some minor tweaks to the documentation. Additionally can we add two more test cases:
- Add a test case where
format_generated_files=true
andgenerated_file_header_size
is set to some value where the@generated
marker could be found. This would better test that whenformat_generated_files=true
is setgenerated_file_header_size
has no effect. - Add a test cast where
format_generated_files=false
andgenerated_file_header_size
is set to some value where the@generated
marker can't be found. This would show that even whenformat_generated_files=false
we'll still format the file if we can't find the@generaged
marker.
Just want to add that I'm open to allowing the user to configure this value, but I haven't had a chance to consider this particular approach and I don't know if this is a significantly high enough priority for us to consider for release in the immediate future |
@calebcartwright Thanks for the honesty. I'll wait for you to consider the approach more closely before I invest more time in this PR. As it stands we are blocked from running rustftm from the CLI (needed to enforce formatting in CI) and must be careful to avoid saving generated files in our editor. Is there a workaround that you would recommend in the mean time? |
To be clear, we'll absolutely support adding an option that allows for this to be controlled, just need a chance to catch up on the back and forth within this thread as well as consider the specifics (as one initial reaction, something bothers me about the currently proposed option name as I don't think it's as self-explanatory as we'd like to see)
Sorry not sure what you're asking. If you want to (temporarily) block folks from running rustfmt, intentionally or accidentally, the best route would be to enable disable_all_formatting. If you want to permit formatting in general but only skip generated files, then ignore would likely be a viable option, assuming you're on a nightly toolchain |
closing since we merged #5993 |
Fixes #5658
FYI @ytmimi