diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-05-01 17:44:25 +0200 |
|---|---|---|
| committer | Yacin Tmimi <yacintmimi@gmail.com> | 2024-05-01 10:53:06 -0600 |
| commit | d5f1200ed6a8e375f963e0c59a8bee45c0018c55 (patch) | |
| tree | 4ea637220f08477092f9a2d93e88b1f6f0250b4f | |
| parent | f781b1b9d34e169a1959feaa79d6cb453dd20aee (diff) | |
| download | rust-d5f1200ed6a8e375f963e0c59a8bee45c0018c55.tar.gz rust-d5f1200ed6a8e375f963e0c59a8bee45c0018c55.zip | |
Add documentation for negated ignored files and add a test for it as well
| -rw-r--r-- | Configurations.md | 9 | ||||
| -rw-r--r-- | src/ignore_path.rs | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/Configurations.md b/Configurations.md index 2d01fb3bb3b..f52c2573154 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1306,6 +1306,15 @@ If you want to ignore every file under the directory where you put your rustfmt. ignore = ["/"] ``` +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`. + ## `imports_indent` Indent style of imports diff --git a/src/ignore_path.rs b/src/ignore_path.rs index 7b5697bec3e..5c25f233ce3 100644 --- a/src/ignore_path.rs +++ b/src/ignore_path.rs @@ -49,4 +49,22 @@ mod test { 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")))); } + + #[nightly_only_test] + #[test] + fn test_negated_ignore_path_set() { + use crate::config::{Config, FileName}; + use crate::ignore_path::IgnorePathSet; + use std::path::{Path, PathBuf}; + + 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("bar_dir/what.rs")))); + assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz/a.rs")))); + assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz/what.rs")))); + } } |
