Skip to content

Commit e80b8f3

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

29 files changed

+134
-134
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
@@ -117,15 +117,6 @@ impl LintRunner {
117117
builder.add(&pattern).unwrap();
118118
}
119119
}
120-
if !oxlintrc.ignore_patterns.is_empty() {
121-
let oxlint_wd = oxlintrc.path.parent().unwrap_or(&self.cwd).to_path_buf();
122-
oxlintrc.ignore_patterns =
123-
Self::adjust_ignore_patterns(&self.cwd, &oxlint_wd, oxlintrc.ignore_patterns);
124-
for pattern in &oxlintrc.ignore_patterns {
125-
let pattern = format!("!{pattern}");
126-
builder.add(&pattern).unwrap();
127-
}
128-
}
129120

130121
let builder = builder.build().unwrap();
131122

@@ -545,30 +536,6 @@ impl LintRunner {
545536
Ok(None)
546537
}
547538
}
548-
549-
fn adjust_ignore_patterns(
550-
base: &PathBuf,
551-
path: &PathBuf,
552-
ignore_patterns: Vec<String>,
553-
) -> Vec<String> {
554-
if base == path {
555-
ignore_patterns
556-
} else {
557-
let relative_ignore_path =
558-
path.strip_prefix(base).map_or_else(|_| PathBuf::from("."), Path::to_path_buf);
559-
560-
ignore_patterns
561-
.into_iter()
562-
.map(|pattern| {
563-
let prefix_len = pattern.bytes().take_while(|&c| c == b'!').count();
564-
let (prefix, pattern) = pattern.split_at(prefix_len);
565-
566-
let adjusted_path = relative_ignore_path.join(pattern);
567-
format!("{prefix}{}", adjusted_path.to_string_lossy().cow_replace('\\', "/"))
568-
})
569-
.collect()
570-
}
571-
}
572539
}
573540

574541
fn print_and_flush_stdout(stdout: &mut dyn Write, message: &str) {
@@ -1041,21 +1008,6 @@ mod test {
10411008
Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
10421009
}
10431010

1044-
#[test]
1045-
fn test_adjust_ignore_patterns() {
1046-
let base = PathBuf::from("/project/root");
1047-
let path = PathBuf::from("/project/root/src");
1048-
let ignore_patterns =
1049-
vec![String::from("target"), String::from("!dist"), String::from("!!dist")];
1050-
1051-
let adjusted_patterns = LintRunner::adjust_ignore_patterns(&base, &path, ignore_patterns);
1052-
1053-
assert_eq!(
1054-
adjusted_patterns,
1055-
vec![String::from("src/target"), String::from("!src/dist"), String::from("!!src/dist")]
1056-
);
1057-
}
1058-
10591011
#[test]
10601012
fn test_nested_config() {
10611013
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 88 rules using 1 threads.
15+
Finished in <variable>ms on 2 files with 88 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 88 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 88 rules using 1 threads.
17+
Finished in <variable>ms on 2 files with 88 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 88 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 88 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 88 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)