Skip to content

Commit 04f9bc0

Browse files
committed
repalce globset to ignore
1 parent db74e49 commit 04f9bc0

File tree

6 files changed

+98
-33
lines changed

6 files changed

+98
-33
lines changed

Cargo.lock

Lines changed: 61 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ bytecount = "0.5"
5757
unicode-width = "0.1.5"
5858
unicode_categories = "0.1.1"
5959
dirs = "1.0.4"
60-
globset = "0.4"
6160

6261
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
6362
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
6463
# for more information.
6564
rustc-workspace-hack = "1.0.0"
65+
ignore = "0.4.6"
6666

6767
[dev-dependencies]
6868
lazy_static = "1.0.0"

src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use syntax::source_map::{FilePathMapping, SourceMap, Span, DUMMY_SP};
1414

1515
use crate::comment::{CharClasses, FullCodeCharKind};
1616
use crate::config::{Config, FileName, Verbosity};
17-
use crate::ignore::IgnorePathSet;
17+
use crate::ignore_path::IgnorePathSet;
1818
use crate::issues::BadIssueSeeker;
1919
use crate::utils::{count_newlines, get_skip_macro_names};
2020
use crate::visitor::{FmtVisitor, SnippetProvider};

src/ignore.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/ignore_path.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// use std::path;
2+
use ignore::{self, gitignore};
3+
4+
use crate::config::{FileName, IgnoreList};
5+
6+
pub struct IgnorePathSet {
7+
ignore_set: gitignore::Gitignore,
8+
}
9+
10+
impl IgnorePathSet {
11+
pub fn from_ignore_list(ignore_list: &IgnoreList) -> Result<Self, ignore::Error> {
12+
let mut ignore_builder = gitignore::GitignoreBuilder::new("");
13+
14+
for ignore_path in ignore_list {
15+
ignore_builder.add_line(None, ignore_path.to_str().unwrap())?;
16+
}
17+
18+
Ok(IgnorePathSet {
19+
ignore_set: ignore_builder.build()?,
20+
})
21+
}
22+
23+
pub fn is_match(&self, file_name: &FileName) -> bool {
24+
match file_name {
25+
FileName::Stdin => false,
26+
FileName::Real(p) => !self
27+
.ignore_set
28+
.matched_path_or_any_parents(p, false)
29+
.is_none(),
30+
}
31+
}
32+
}

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::path::PathBuf;
2020
use std::rc::Rc;
2121

2222
use failure::Fail;
23+
use ignore;
2324
use syntax::{ast, parse::DirectoryOwnership};
2425

2526
use crate::comment::LineClasses;
@@ -46,7 +47,7 @@ mod comment;
4647
pub(crate) mod config;
4748
mod expr;
4849
pub(crate) mod formatting;
49-
mod ignore;
50+
mod ignore_path;
5051
mod imports;
5152
mod issues;
5253
mod items;
@@ -113,7 +114,7 @@ pub enum ErrorKind {
113114
LostComment,
114115
/// Invalid glob pattern in `ignore` configuration option.
115116
#[fail(display = "Invalid glob pattern found in ignore list: {}", _0)]
116-
InvalidGlobPattern(globset::Error),
117+
InvalidGlobPattern(ignore::Error),
117118
}
118119

119120
impl ErrorKind {

0 commit comments

Comments
 (0)