Skip to content

Commit ca998c8

Browse files
committed
feat(linter): support ignorePatterns for nested configs
1 parent ae8a13b commit ca998c8

23 files changed

+127
-130
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
@@ -119,15 +119,6 @@ impl Runner for LintRunner {
119119
builder.add(&pattern).unwrap();
120120
}
121121
}
122-
if !oxlintrc.ignore_patterns.is_empty() {
123-
let oxlint_wd = oxlintrc.path.parent().unwrap_or(&self.cwd).to_path_buf();
124-
oxlintrc.ignore_patterns =
125-
Self::adjust_ignore_patterns(&self.cwd, &oxlint_wd, oxlintrc.ignore_patterns);
126-
for pattern in &oxlintrc.ignore_patterns {
127-
let pattern = format!("!{pattern}");
128-
builder.add(&pattern).unwrap();
129-
}
130-
}
131122

132123
let builder = builder.build().unwrap();
133124

@@ -517,30 +508,6 @@ impl LintRunner {
517508
Ok(None)
518509
}
519510
}
520-
521-
fn adjust_ignore_patterns(
522-
base: &PathBuf,
523-
path: &PathBuf,
524-
ignore_patterns: Vec<String>,
525-
) -> Vec<String> {
526-
if base == path {
527-
ignore_patterns
528-
} else {
529-
let relative_ignore_path =
530-
path.strip_prefix(base).map_or_else(|_| PathBuf::from("."), Path::to_path_buf);
531-
532-
ignore_patterns
533-
.into_iter()
534-
.map(|pattern| {
535-
let prefix_len = pattern.bytes().take_while(|&c| c == b'!').count();
536-
let (prefix, pattern) = pattern.split_at(prefix_len);
537-
538-
let adjusted_path = relative_ignore_path.join(pattern);
539-
format!("{prefix}{}", adjusted_path.to_string_lossy().cow_replace('\\', "/"))
540-
})
541-
.collect()
542-
}
543-
}
544511
}
545512

546513
fn print_and_flush_stdout(stdout: &mut dyn Write, message: &str) {
@@ -1030,21 +997,6 @@ mod test {
1030997
Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
1031998
}
1032999

1033-
#[test]
1034-
fn test_adjust_ignore_patterns() {
1035-
let base = PathBuf::from("/project/root");
1036-
let path = PathBuf::from("/project/root/src");
1037-
let ignore_patterns =
1038-
vec![String::from("target"), String::from("!dist"), String::from("!!dist")];
1039-
1040-
let adjusted_patterns = LintRunner::adjust_ignore_patterns(&base, &path, ignore_patterns);
1041-
1042-
assert_eq!(
1043-
adjusted_patterns,
1044-
vec![String::from("src/target"), String::from("!src/dist"), String::from("!!src/dist")]
1045-
);
1046-
}
1047-
10481000
#[test]
10491001
fn test_nested_config() {
10501002
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)