Skip to content

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

Merged
merged 1 commit into from
May 1, 2024

Conversation

GuillaumeGomez
Copy link
Member

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. :)

Copy link
Contributor

@ytmimi ytmimi left a 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.

Comment on lines 1309 to 1317
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`.

Copy link
Contributor

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:

Suggested change
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`.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 44 to 68
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"))));
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Member Author

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. ;)

Copy link
Contributor

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.

@GuillaumeGomez
Copy link
Member Author

Updated!

@GuillaumeGomez GuillaumeGomez force-pushed the negated-ignore branch 2 times, most recently from 839b5ca to 621efc0 Compare May 1, 2024 16:13
@GuillaumeGomez
Copy link
Member Author

Finally fixed the formatting. ^^'

Strangely enough, if I run cargo fmt on rustfmt, it formats other files that fail tests in CI.

@ytmimi
Copy link
Contributor

ytmimi commented May 1, 2024

Finally fixed the formatting. ^^'

Strangely enough, if I run cargo fmt on rustfmt, it formats other files that fail tests in CI.

Interesting! I wonder what's going on there

@ytmimi ytmimi merged commit d5f1200 into rust-lang:master May 1, 2024
27 checks passed
@GuillaumeGomez GuillaumeGomez deleted the negated-ignore branch May 1, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants