-
Notifications
You must be signed in to change notification settings - Fork 166
Exclusion Patterns for Lines and Branches #416
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
Merged
+507
−87
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7b1b878
Fix tests on Windows
78b8941
Fix non-compiling bench
af729bf
Add line and branch exclusion
7aee322
Fix formatting on touched files
4dec6f4
PR Nits and Build Improvements
d6c8baf
Implement filter parallelism
852fd2f
Fix formatting
1f58ba5
Make arg names consistent with existing args
5b91a0a
Properly fix names
7ab55af
Properly retrieve arg names
3ffd066
Implement PR feedback.
a3814f6
Merge remote-tracking branch 'upstream/master'
ba4f67c
Fix cargo lock.
d6295b1
Merge remote-tracking branch 'upstream/master'
4f01485
PR feedback
5490d2d
PR feedback and fix formatting on touched files
7e12d8c
Remove matches and fix remaining lines
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,134 @@ | ||
| use regex::Regex; | ||
| use std::path::PathBuf; | ||
|
|
||
| pub enum FilterType { | ||
| Line(u32), | ||
| Branch(u32), | ||
| Both(u32), | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct FileFilter { | ||
| excl_line: Option<Regex>, | ||
| excl_start: Option<Regex>, | ||
| excl_stop: Option<Regex>, | ||
| excl_br_line: Option<Regex>, | ||
| excl_br_start: Option<Regex>, | ||
| excl_br_stop: Option<Regex>, | ||
| } | ||
|
|
||
| impl FileFilter { | ||
| pub fn new( | ||
| excl_line: Option<Regex>, | ||
| excl_start: Option<Regex>, | ||
| excl_stop: Option<Regex>, | ||
| excl_br_line: Option<Regex>, | ||
| excl_br_start: Option<Regex>, | ||
| excl_br_stop: Option<Regex>, | ||
| ) -> Self { | ||
| Self { | ||
| excl_line, | ||
| excl_start, | ||
| excl_stop, | ||
| excl_br_line, | ||
| excl_br_start, | ||
| excl_br_stop, | ||
| } | ||
| } | ||
|
|
||
| pub fn create(&self, file: &PathBuf) -> Vec<FilterType> { | ||
| if self.excl_line.is_none() | ||
| && self.excl_start.is_none() | ||
| && self.excl_br_line.is_none() | ||
| && self.excl_br_start.is_none() | ||
| { | ||
| return Vec::new(); | ||
| } | ||
|
|
||
| let file = std::fs::read_to_string(file); | ||
| let file = if let Ok(file) = file { | ||
| file | ||
| } else { | ||
| return Vec::new(); | ||
| }; | ||
|
|
||
| let mut ignore_br = false; | ||
| let mut ignore = false; | ||
|
|
||
| file.split('\n') | ||
| .enumerate() | ||
| .filter_map(move |(number, line)| { | ||
| // Line numbers are 1-based. | ||
| let number = (number + 1) as u32; | ||
|
|
||
| // The file is split on \n, which may result in a trailing \r | ||
| // on Windows. Remove it. | ||
| let line = if line.ends_with('\r') { | ||
| &line[..(line.len() - 1)] | ||
| } else { | ||
| line | ||
| }; | ||
|
|
||
| // End a branch ignore region. Region endings are exclusive. | ||
| if ignore_br | ||
| && self | ||
| .excl_br_stop | ||
| .as_ref() | ||
| .map_or(false, |f| f.is_match(line)) | ||
| { | ||
| ignore_br = false | ||
| } | ||
|
|
||
| // End a line ignore region. Region endings are exclusive. | ||
| if ignore && self.excl_stop.as_ref().map_or(false, |f| f.is_match(line)) { | ||
| ignore = false | ||
| } | ||
|
|
||
| // Start a branch ignore region. Region starts are inclusive. | ||
| if !ignore_br | ||
| && self | ||
| .excl_br_start | ||
| .as_ref() | ||
| .map_or(false, |f| f.is_match(line)) | ||
| { | ||
| ignore_br = true; | ||
| } | ||
|
|
||
| // Start a line ignore region. Region starts are inclusive. | ||
| if !ignore && self.excl_start.as_ref().map_or(false, |f| f.is_match(line)) { | ||
| ignore = true; | ||
| } | ||
|
|
||
| if ignore_br { | ||
| // Consuming code has to eliminate each of these | ||
| // individually, so it has to know when both are ignored vs. | ||
| // either. | ||
| if ignore { | ||
| Some(FilterType::Both(number)) | ||
| } else { | ||
| Some(FilterType::Branch(number)) | ||
| } | ||
| } else if ignore { | ||
| Some(FilterType::Line(number)) | ||
| } else if self | ||
| .excl_br_line | ||
| .as_ref() | ||
| .map_or(false, |f| f.is_match(line)) | ||
| { | ||
| // Single line exclusion. If single line exclusions occur | ||
| // inside a region they are meaningless (would be applied | ||
| // anway), so they are lower priority. | ||
| if self.excl_line.as_ref().map_or(false, |f| f.is_match(line)) { | ||
| Some(FilterType::Both(number)) | ||
| } else { | ||
| Some(FilterType::Branch(number)) | ||
| } | ||
| } else if self.excl_line.as_ref().map_or(false, |f| f.is_match(line)) { | ||
| Some(FilterType::Line(number)) | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| .collect() | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.