-
Notifications
You must be signed in to change notification settings - Fork 909
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1050,15 +1050,23 @@ Max width for code snippets included in doc comments. Only used if [`format_code | |
|
||
## `format_generated_files` | ||
|
||
Format generated files. A file is considered generated | ||
if any of the first five lines contain a `@generated` comment marker. | ||
Format generated files. A file is considered generated if any of the first several lines contain a `@generated` comment marker. The number of lines to check is configured by `generated_file_header_size`. | ||
|
||
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. | ||
|
||
- **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 commentThe 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 commentThe 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. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add a |
||
## `format_macro_matchers` | ||
|
||
Format the metavariable matching patterns in macros. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/// Returns `true` if the given span is a part of generated files. | ||
pub(super) fn is_generated_file(original_snippet: &str) -> bool { | ||
pub(super) fn is_generated_file(original_snippet: &str, header_size: usize) -> bool { | ||
original_snippet | ||
.lines() | ||
.take(5) // looking for marker only in the beginning of the file | ||
.take(header_size) // looking for marker only in the beginning of the file | ||
.any(|line| line.contains("@generated")) | ||
} |
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 whenformat_generated_files
is false. Whenformat_generated_files
is true, this option has no effect.