Skip to content

Commit 83c7ff0

Browse files
committed
feat(linter): support ignorePatterns for nested configs
1 parent 9b14fbc commit 83c7ff0

23 files changed

+123
-126
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/src/lint.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,6 @@ impl Runner for LintRunner {
109109
builder.add(&pattern).unwrap();
110110
}
111111
}
112-
if !oxlintrc.ignore_patterns.is_empty() {
113-
let oxlint_wd = oxlintrc.path.parent().unwrap_or(&self.cwd).to_path_buf();
114-
oxlintrc.ignore_patterns =
115-
Self::adjust_ignore_patterns(&self.cwd, &oxlint_wd, oxlintrc.ignore_patterns);
116-
for pattern in &oxlintrc.ignore_patterns {
117-
let pattern = format!("!{pattern}");
118-
builder.add(&pattern).unwrap();
119-
}
120-
}
121112

122113
let builder = builder.build().unwrap();
123114

@@ -538,30 +529,6 @@ impl LintRunner {
538529
Err("No oxlint config file found".to_string())
539530
}
540531
}
541-
542-
fn adjust_ignore_patterns(
543-
base: &PathBuf,
544-
path: &PathBuf,
545-
ignore_patterns: Vec<String>,
546-
) -> Vec<String> {
547-
if base == path {
548-
ignore_patterns
549-
} else {
550-
let relative_ignore_path =
551-
path.strip_prefix(base).map_or_else(|_| PathBuf::from("."), Path::to_path_buf);
552-
553-
ignore_patterns
554-
.into_iter()
555-
.map(|pattern| {
556-
let prefix_len = pattern.bytes().take_while(|&c| c == b'!').count();
557-
let (prefix, pattern) = pattern.split_at(prefix_len);
558-
559-
let adjusted_path = relative_ignore_path.join(pattern);
560-
format!("{prefix}{}", adjusted_path.to_string_lossy().cow_replace('\\', "/"))
561-
})
562-
.collect()
563-
}
564-
}
565532
}
566533

567534
fn print_and_flush_stdout(stdout: &mut dyn Write, message: &str) {
@@ -1044,21 +1011,6 @@ mod test {
10441011
Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
10451012
}
10461013

1047-
#[test]
1048-
fn test_adjust_ignore_patterns() {
1049-
let base = PathBuf::from("/project/root");
1050-
let path = PathBuf::from("/project/root/src");
1051-
let ignore_patterns =
1052-
vec![String::from("target"), String::from("!dist"), String::from("!!dist")];
1053-
1054-
let adjusted_patterns = LintRunner::adjust_ignore_patterns(&base, &path, ignore_patterns);
1055-
1056-
assert_eq!(
1057-
adjusted_patterns,
1058-
vec![String::from("src/target"), String::from("!src/dist"), String::from("!!src/dist")]
1059-
);
1060-
}
1061-
10621014
#[test]
10631015
fn test_nested_config() {
10641016
let args = &[];

apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension@oxlint.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ working directory:
1212
help: Delete this file or add some code to it.
1313
1414
Found 1 warning and 0 errors.
15-
Finished in <variable>ms on 1 file with 87 rules using 1 threads.
15+
Finished in <variable>ms on 2 files with 87 rules using 1 threads.
1616
----------
1717
CLI result: LintSucceeded
1818
----------

apps/oxlint/src/snapshots/_-c fixtures__config_ignore_patterns__ignore_extension__eslintrc.json fixtures__config_ignore_patterns__ignore_extension__main.js@oxlint.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ source: apps/oxlint/src/tester.rs
55
arguments: -c fixtures/config_ignore_patterns/ignore_extension/eslintrc.json fixtures/config_ignore_patterns/ignore_extension/main.js
66
working directory:
77
----------
8-
Finished in <variable>ms on 0 files using 1 threads.
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 1 file with 87 rules using 1 threads.
910
----------
10-
CLI result: LintNoFilesFound
11+
CLI result: LintSucceeded
1112
----------

apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__ignore_directory_-c eslintrc.json@oxlint.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ working directory: fixtures/config_ignore_patterns/ignore_directory
1414
help: Delete this file or add some code to it.
1515
1616
Found 1 warning and 0 errors.
17-
Finished in <variable>ms on 1 file with 87 rules using 1 threads.
17+
Finished in <variable>ms on 2 files with 87 rules using 1 threads.
1818
----------
1919
CLI result: LintSucceeded
2020
----------

apps/oxlint/src/snapshots/fixtures__config_ignore_patterns__with_oxlintrc_-c .__test__eslintrc.json --ignore-pattern _.ts .@oxlint.snap

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ source: apps/oxlint/src/tester.rs
55
arguments: -c ./test/eslintrc.json --ignore-pattern *.ts .
66
working directory: fixtures/config_ignore_patterns/with_oxlintrc
77
----------
8-
9-
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-empty-file.html\eslint-plugin-unicorn(no-empty-file)]8;;\: Empty files are not allowed.
10-
,-[main.js:1:1]
11-
`----
12-
help: Delete this file or add some code to it.
13-
14-
Found 1 warning and 0 errors.
8+
Found 0 warnings and 0 errors.
159
Finished in <variable>ms on 1 file with 87 rules using 1 threads.
1610
----------
1711
CLI result: LintSucceeded

apps/oxlint/src/snapshots/fixtures__ignore_file_current_dir_ .@oxlint.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ arguments:
66
working directory: fixtures/ignore_file_current_dir
77
----------
88
Found 0 warnings and 0 errors.
9-
Finished in <variable>ms on 0 files with 87 rules using 1 threads.
9+
Finished in <variable>ms on 2 files using 1 threads.
1010
----------
1111
CLI result: LintSucceeded
1212
----------
@@ -16,7 +16,7 @@ arguments: .
1616
working directory: fixtures/ignore_file_current_dir
1717
----------
1818
Found 0 warnings and 0 errors.
19-
Finished in <variable>ms on 0 files with 87 rules using 1 threads.
19+
Finished in <variable>ms on 2 files using 1 threads.
2020
----------
2121
CLI result: LintSucceeded
2222
----------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"no-debugger": "error"
4+
}
5+
}

0 commit comments

Comments
 (0)