-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config option
generated_marker_line_search_limit
(#5993)
`generated_marker_line_search_limit` allows users to configure how many lines rustfmt should search for an `@generated` marker comment when `format_generated_files=false` --------- Co-authored-by: Jordan Eldredge <[email protected]>
- Loading branch information
1 parent
6356fca
commit bf96731
Showing
14 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
use crate::Config; | ||
|
||
/// 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, config: &Config) -> bool { | ||
original_snippet | ||
.lines() | ||
.take(5) // looking for marker only in the beginning of the file | ||
// looking for marker only in the beginning of the file | ||
.take(config.generated_marker_line_search_limit()) | ||
.any(|line| line.contains("@generated")) | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/source/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 15 | ||
|
||
fn main() | ||
{ | ||
println!("hello, world") | ||
; | ||
} | ||
|
||
// @generated |
10 changes: 10 additions & 0 deletions
10
tests/source/configs/format_generated_files/false_with_marker_out_scope_size.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 1 | ||
|
||
fn main() | ||
{ | ||
println!("hello, world") | ||
; | ||
} | ||
|
||
// @generated |
9 changes: 9 additions & 0 deletions
9
tests/source/configs/format_generated_files/false_with_zero_search_limit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 0 | ||
|
||
// @generated | ||
fn main() { | ||
println!("hello, world") | ||
; | ||
} | ||
// @generated |
10 changes: 10 additions & 0 deletions
10
tests/source/configs/format_generated_files/true_with_marker_in_scope_size.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rustfmt-format_generated_files: true | ||
// rustfmt-generated_marker_line_search_limit: 20 | ||
|
||
fn main() | ||
{ | ||
println!("hello, world") | ||
; | ||
} | ||
|
||
// @generated |
9 changes: 9 additions & 0 deletions
9
tests/source/configs/format_generated_files/true_with_marker_not_in_header.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// rustfmt-format_generated_files: true | ||
|
||
fn main() | ||
{ | ||
println!("hello, world") | ||
; | ||
} | ||
|
||
// @generated |
10 changes: 10 additions & 0 deletions
10
tests/target/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 15 | ||
|
||
fn main() | ||
{ | ||
println!("hello, world") | ||
; | ||
} | ||
|
||
// @generated |
8 changes: 8 additions & 0 deletions
8
tests/target/configs/format_generated_files/false_with_marker_out_scope_size.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 1 | ||
|
||
fn main() { | ||
println!("hello, world"); | ||
} | ||
|
||
// @generated |
8 changes: 8 additions & 0 deletions
8
tests/target/configs/format_generated_files/false_with_zero_search_limit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-format_generated_files: false | ||
// rustfmt-generated_marker_line_search_limit: 0 | ||
|
||
// @generated | ||
fn main() { | ||
println!("hello, world"); | ||
} | ||
// @generated |
8 changes: 8 additions & 0 deletions
8
tests/target/configs/format_generated_files/true_with_marker_in_scope_size.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-format_generated_files: true | ||
// rustfmt-generated_marker_line_search_limit: 20 | ||
|
||
fn main() { | ||
println!("hello, world"); | ||
} | ||
|
||
// @generated |
7 changes: 7 additions & 0 deletions
7
tests/target/configs/format_generated_files/true_with_marker_not_in_header.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// rustfmt-format_generated_files: true | ||
|
||
fn main() { | ||
println!("hello, world"); | ||
} | ||
|
||
// @generated |