-
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 to allow generated lines scan to be configurable
- Loading branch information
1 parent
da7f678
commit dff3954
Showing
4 changed files
with
46 additions
and
8 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,30 @@ | ||
/// 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, scan_number_of_lines: usize) -> bool { | ||
original_snippet | ||
.lines() | ||
.take(5) // looking for marker only in the beginning of the file | ||
.take(scan_number_of_lines) | ||
.any(|line| line.contains("@generated")) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn detect_generated_file_simple() { | ||
let snippet = "@generated"; | ||
assert!(is_generated_file(snippet, 1)); | ||
} | ||
|
||
#[test] | ||
fn detect_generated_file_5_lines() { | ||
let snippet = "\n \n \n \n @generated"; | ||
assert!(is_generated_file(snippet, 5)); | ||
} | ||
|
||
#[test] | ||
fn no_detect_generated_file_5_lines() { | ||
let snippet = "\n \n \n \n \n @generated"; | ||
assert!(!is_generated_file(snippet, 5)); | ||
} | ||
} |