Skip to content

Commit eb2f15d

Browse files
committed
fix(linter): parse ignorePatterns with gitignore syntax
1 parent 76a9865 commit eb2f15d

File tree

8 files changed

+52
-10
lines changed

8 files changed

+52
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignorePatterns": [
3+
"ignored_dir"
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debugger;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignorePatterns": [
3+
"ignored_dir"
4+
]
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debugger;

apps/oxlint/src/lint.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ mod test {
667667
.test_and_snapshot_multiple(&[args1, args2]);
668668
}
669669

670+
#[test]
671+
// https://github.com/oxc-project/oxc/issues/13204
672+
fn ignore_pattern_non_glob_syntax() {
673+
let args1 = &[];
674+
let args2 = &["."];
675+
Tester::new()
676+
.with_cwd("fixtures/ignore_pattern_non_glob_syntax".into())
677+
.test_and_snapshot_multiple(&[args1, args2]);
678+
}
679+
670680
#[test]
671681
fn filter_allow_all() {
672682
let args = &["-A", "all", "fixtures/linter"];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments:
6+
working directory: fixtures/ignore_pattern_non_glob_syntax
7+
----------
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 0 files using 1 threads.
10+
----------
11+
CLI result: LintSucceeded
12+
----------
13+
14+
##########
15+
arguments: .
16+
working directory: fixtures/ignore_pattern_non_glob_syntax
17+
----------
18+
Found 0 warnings and 0 errors.
19+
Finished in <variable>ms on 0 files using 1 threads.
20+
----------
21+
CLI result: LintSucceeded
22+
----------

crates/oxc_linter/src/config/config_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ impl ConfigStore {
330330
}
331331

332332
pub fn should_ignore(&self, path: &Path) -> bool {
333-
self.get_related_config(path)
334-
.ignore_patterns()
335-
.is_some_and(|ignore_patterns| ignore_patterns.matched(path, false).is_ignore())
333+
self.get_related_config(path).ignore_patterns().is_some_and(|ignore_patterns| {
334+
ignore_patterns.matched_path_or_any_parents(path, false).is_ignore()
335+
})
336336
}
337337

338338
// NOTE: This function is not crate visible because it is used in `oxlint` as well to resolve configs

crates/oxc_linter/src/config/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub use config_builder::{ConfigBuilderError, ConfigStoreBuilder};
1414
pub use config_store::{Config, ConfigStore, ResolvedLinterState};
1515
pub use env::OxlintEnv;
1616
pub use globals::{GlobalValue, OxlintGlobals};
17-
use ignore::overrides::OverrideBuilder;
17+
use ignore::gitignore::{Gitignore, GitignoreBuilder};
1818
pub use overrides::OxlintOverrides;
1919
pub use oxlintrc::Oxlintrc;
2020
pub use plugins::{BuiltinLintPlugins, LintPlugins};
2121
pub use rules::{ESLintRule, OxlintRules};
2222
pub use settings::{OxlintSettings, jsdoc::JSDocPluginSettings};
2323

24-
pub type ResolvedIgnorePatterns = ignore::overrides::Override;
24+
pub type ResolvedIgnorePatterns = Gitignore;
2525

2626
#[derive(Debug, Default, Clone)]
2727
pub struct LintConfig {
@@ -61,15 +61,13 @@ impl LintConfig {
6161
// expect that every oxlint config file with "ignorePatterns" provides its config path with parent.
6262
// for the default config the path is empty, but there should be no ignore patterns
6363
let oxlint_wd = config_path.parent()?.to_path_buf();
64-
65-
let mut builder = OverrideBuilder::new(&oxlint_wd);
64+
let mut gitignore_builder = GitignoreBuilder::new(&oxlint_wd);
6665

6766
for pattern in ignore_patterns {
68-
let pattern = format!("!{pattern}");
69-
builder.add(&pattern).unwrap();
67+
gitignore_builder.add_line(None, pattern).unwrap();
7068
}
7169

72-
builder.build().ok()
70+
gitignore_builder.build().ok()
7371
}
7472
}
7573

0 commit comments

Comments
 (0)