Skip to content

Commit 3999d64

Browse files
committed
Simplify IgnoreList
1 parent 84ad70c commit 3999d64

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

Configurations.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,8 +2149,7 @@ Skip formatting the specified files and directories.
21492149
If you want to ignore specific files, put the following to your config file:
21502150

21512151
```toml
2152-
[ignore]
2153-
files = [
2152+
ignore = [
21542153
"src/types.rs",
21552154
"src/foo/bar.rs",
21562155
]
@@ -2159,8 +2158,7 @@ files = [
21592158
If you want to ignore every file under `examples/`, put the following to your config file:
21602159

21612160
```toml
2162-
[ignore]
2163-
directories = [
2161+
ignore [
21642162
"examples",
21652163
]
21662164
```

src/config/options.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,12 @@ impl ::std::str::FromStr for WidthHeuristics {
252252

253253
/// A set of directories, files and modules that rustfmt should ignore.
254254
#[derive(Default, Deserialize, Serialize, Clone, Debug)]
255-
pub struct IgnoreList {
256-
directories: Option<HashSet<PathBuf>>,
257-
files: Option<HashSet<PathBuf>>,
258-
}
255+
pub struct IgnoreList(HashSet<PathBuf>);
259256

260257
impl IgnoreList {
261-
fn add_prefix_inner(set: &HashSet<PathBuf>, dir: &Path) -> HashSet<PathBuf> {
262-
set.iter()
258+
pub fn add_prefix(&mut self, dir: &Path) {
259+
self.0 = self.0
260+
.iter()
263261
.map(|s| {
264262
if s.has_root() {
265263
s.clone()
@@ -269,29 +267,13 @@ impl IgnoreList {
269267
path
270268
}
271269
})
272-
.collect()
273-
}
274-
275-
pub fn add_prefix(&mut self, dir: &Path) {
276-
macro add_prefix_inner_with ($($field: ident),* $(,)*) {
277-
$(if let Some(set) = self.$field.as_mut() {
278-
*set = IgnoreList::add_prefix_inner(set, dir);
279-
})*
280-
}
281-
282-
add_prefix_inner_with!(directories, files);
270+
.collect();
283271
}
284272

285-
fn is_ignore_file(&self, path: &Path) -> bool {
286-
self.files.as_ref().map_or(false, |set| set.contains(path))
287-
}
288-
289-
fn is_under_ignore_dir(&self, path: &Path) -> bool {
290-
if let Some(ref dirs) = self.directories {
291-
for dir in dirs {
292-
if path.starts_with(dir) {
293-
return true;
294-
}
273+
fn skip_file_inner(&self, file: &Path) -> bool {
274+
for path in &self.0 {
275+
if file.starts_with(path) {
276+
return true;
295277
}
296278
}
297279

@@ -300,7 +282,7 @@ impl IgnoreList {
300282

301283
pub fn skip_file(&self, file: &FileName) -> bool {
302284
if let FileName::Real(ref path) = file {
303-
self.is_ignore_file(path) || self.is_under_ignore_dir(path)
285+
self.skip_file_inner(path)
304286
} else {
305287
false
306288
}

0 commit comments

Comments
 (0)