@@ -3,7 +3,7 @@ use std::{
33 sync:: mpsc,
44} ;
55
6- use ignore:: overrides:: OverrideBuilder ;
6+ use ignore:: { gitignore :: GitignoreBuilder , overrides:: OverrideBuilder } ;
77
88use oxc_formatter:: get_supported_source_type;
99use oxc_span:: SourceType ;
@@ -33,6 +33,9 @@ impl Walk {
3333 }
3434 }
3535
36+ // NOTE: We are using `OverrideBuilder` only for exclusion.
37+ // This means there is no way to "re-include" a file once ignored.
38+
3639 // Treat all `!` prefixed patterns as overrides to exclude
3740 if !exclude_patterns. is_empty ( ) {
3841 let mut builder = OverrideBuilder :: new ( cwd) ;
@@ -46,11 +49,15 @@ impl Walk {
4649 }
4750
4851 // Handle ignore files
49- for ignore_path in load_ignore_paths ( cwd, ignore_paths) {
50- if inner. add_ignore ( & ignore_path) . is_some ( ) {
52+ let mut builder = GitignoreBuilder :: new ( cwd) ;
53+ for ignore_path in & load_ignore_paths ( cwd, ignore_paths) {
54+ if builder. add ( ignore_path) . is_some ( ) {
5155 return Err ( format ! ( "Failed to add ignore file: {}" , ignore_path. display( ) ) ) ;
5256 }
5357 }
58+ // TODO: Support config.ignorePatterns
59+ // Use `builder.add_line(None, pattern_str)` here
60+ let ignores = builder. build ( ) . map_err ( |_| "Failed to build ignores" . to_string ( ) ) ?;
5461
5562 // NOTE: If return `false` here, it will not be `visit()`ed at all
5663 inner. filter_entry ( move |entry| {
@@ -59,7 +66,9 @@ impl Walk {
5966 return false ;
6067 } ;
6168
62- if file_type. is_dir ( ) {
69+ let is_dir = file_type. is_dir ( ) ;
70+
71+ if is_dir {
6372 // We are setting `.hidden(false)` on the `WalkBuilder` below,
6473 // it means we want to include hidden files and directories.
6574 // However, we (and also Prettier) still skip traversing certain directories.
@@ -78,6 +87,12 @@ impl Walk {
7887 }
7988 }
8089
90+ // Check ignore files, patterns
91+ let matched = ignores. matched ( entry. path ( ) , is_dir) ;
92+ if matched. is_ignore ( ) && !matched. is_whitelist ( ) {
93+ return false ;
94+ }
95+
8196 // NOTE: We can also check `get_supported_source_type()` here to skip.
8297 // But we want to pass parsed `SourceType` to `FormatService`,
8398 // so we do it later in the visitor instead.
0 commit comments