-
Notifications
You must be signed in to change notification settings - Fork 928
Add documentation for negated ignored files and add a test for it as well #6155
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
Conversation
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 this. A few minor notes, but overall I think this is a great addition to the docs.
Configurations.md
Outdated
If you want to allow specific paths, use `!`: | ||
|
||
```toml | ||
ignore = ["bar_dir/*", "!bar_dir/*/what.rs"] | ||
``` | ||
|
||
In this case, all files under `bar_dir` will be ignored, except files like `bar_dir/sub/what.rs` | ||
or `bar_dir/another/what.rs`. | ||
|
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.
To be totally honest, I didn't even know this was possible. Nice to see that it's doable 😁! I might rephrase it slightly:
If you want to allow specific paths, use `!`: | |
```toml | |
ignore = ["bar_dir/*", "!bar_dir/*/what.rs"] | |
``` | |
In this case, all files under `bar_dir` will be ignored, except files like `bar_dir/sub/what.rs` | |
or `bar_dir/another/what.rs`. | |
If you want to allow specific paths that would otherwise be ignored, prefix those paths with a `!`: | |
```toml | |
ignore = ["bar_dir/*", "!bar_dir/*/what.rs"] | |
``` | |
In this case, all files under `bar_dir` will be ignored, except files like `bar_dir/sub/what.rs` | |
or `bar_dir/another/what.rs`. | |
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.
👍
src/ignore_path.rs
Outdated
let config = Config::from_toml( | ||
r#"ignore = ["foo.rs", "bar_dir/*", "!bar_dir/*/what.rs"]"#, | ||
Path::new(""), | ||
) | ||
.unwrap(); | ||
let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap(); | ||
|
||
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs")))); | ||
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs")))); | ||
assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs")))); | ||
assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz/what.rs")))); |
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.
Would you mind creating a new test for this "allowed path in ignored directory" case.
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.
You mean a different test apart from this one?
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.
With extra thought, I think that's what you meant so doing that. ;)
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.
Yeah, that's what I meant. Sorry for any confusion.
af0a2ee
to
11898de
Compare
Updated! |
839b5ca
to
621efc0
Compare
621efc0
to
39bae89
Compare
Finally fixed the formatting. ^^' Strangely enough, if I run |
Interesting! I wonder what's going on there |
I was looking into the source code to check how to add support for negated ignore because I didn't find any mention of it into the documentation until I went through the
ignore
crate source code, here in particular. Would have saved me a lot of time if such an example existed so here we are. :)