@@ -16,6 +16,7 @@ impl Walk {
1616 pub fn build (
1717 cwd : & PathBuf ,
1818 paths : & [ PathBuf ] ,
19+ ignore_paths : & [ PathBuf ] ,
1920 with_node_modules : bool ,
2021 ) -> Result < Self , String > {
2122 let ( target_paths, exclude_patterns) = normalize_paths ( cwd, paths) ;
@@ -44,12 +45,12 @@ impl Walk {
4445 inner. overrides ( overrides) ;
4546 }
4647
47- // TODO: Support ignoring files
48- // --ignore-path PATH1 --ignore-path PATH2
49- // or default cwd/{.gitignore,.prettierignore}
50- // if let Some(err) = inner.add_ignore(path) {
51- // return Err(format!("Failed to add ignore file: {}", err));
52- // }
48+ // Handle ignore files
49+ for ignore_path in load_ignore_paths ( cwd , ignore_paths ) {
50+ if inner . add_ignore ( & ignore_path ) . is_some ( ) {
51+ return Err ( format ! ( "Failed to add ignore file: {}" , ignore_path . display ( ) ) ) ;
52+ }
53+ }
5354
5455 // NOTE: If return `false` here, it will not be `visit()`ed at all
5556 inner. filter_entry ( move |entry| {
@@ -92,7 +93,10 @@ impl Walk {
9293 . hidden ( false )
9394 // Do not respect `.gitignore` automatically, we handle it manually
9495 . ignore ( false )
96+ . parents ( false )
9597 . git_global ( false )
98+ . git_ignore ( false )
99+ . git_exclude ( false )
96100 . build_parallel ( ) ;
97101 Ok ( Self { inner } )
98102 }
@@ -155,6 +159,25 @@ fn normalize_paths(cwd: &Path, input_paths: &[PathBuf]) -> (Vec<PathBuf>, Vec<St
155159 ( target_paths, exclude_patterns)
156160}
157161
162+ fn load_ignore_paths ( cwd : & Path , ignore_paths : & [ PathBuf ] ) -> Vec < PathBuf > {
163+ // If specified, just resolves absolute paths
164+ if !ignore_paths. is_empty ( ) {
165+ return ignore_paths
166+ . iter ( )
167+ . map ( |path| if path. is_absolute ( ) { path. clone ( ) } else { cwd. join ( path) } )
168+ . collect ( ) ;
169+ }
170+
171+ // Else, search for default ignore files in cwd
172+ [ ".gitignore" , ".prettierignore" ]
173+ . iter ( )
174+ . filter_map ( |file_name| {
175+ let path = cwd. join ( file_name) ;
176+ if path. exists ( ) { Some ( path) } else { None }
177+ } )
178+ . collect :: < Vec < _ > > ( )
179+ }
180+
158181// ---
159182
160183pub struct WalkEntry {
0 commit comments