Skip to content

Commit

Permalink
Add documentation for negated ignored files and add a test for it as …
Browse files Browse the repository at this point in the history
…well
  • Loading branch information
GuillaumeGomez authored and ytmimi committed May 1, 2024
1 parent f781b1b commit d5f1200
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/ignore_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))));
}
}

0 comments on commit d5f1200

Please sign in to comment.