Skip to content

Commit a9284da

Browse files
committed
fix(oxlint): canonicalize paths provided as args
closes #9023
1 parent e3b6eeb commit a9284da

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ignorePatterns": [
3+
"foo.js",
4+
"a/bar.js"
5+
],
6+
"rules": {
7+
"no-debugger": "deny"
8+
}
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
debugger
2+
console.log("Don't lint me!!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
debugger
2+
console.log("Don't lint me!!")

apps/oxlint/src/lint.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ impl Runner for LintRunner {
128128
let (ignore, _err) = Gitignore::new(&ignore_options.ignore_path);
129129

130130
paths.retain_mut(|p| {
131-
// Append cwd to all paths
132-
let mut path = self.cwd.join(&p);
131+
// Try to prepend cwd to all paths
132+
let Ok(mut path) = self.cwd.join(&p).canonicalize() else {
133+
return false;
134+
};
133135

134136
std::mem::swap(p, &mut path);
135137

@@ -580,6 +582,16 @@ mod test {
580582
Tester::new().test_and_snapshot(args);
581583
}
582584

585+
#[test]
586+
// https://github.com/oxc-project/oxc/issues/9023
587+
fn ignore_file_current_dir() {
588+
let args1 = &[];
589+
let args2 = &["."];
590+
Tester::new()
591+
.with_cwd("fixtures/ignore_file_current_dir".into())
592+
.test_and_snapshot_multiple(&[args1, args2]);
593+
}
594+
583595
#[test]
584596
fn filter_allow_all() {
585597
let args = &["-A", "all", "fixtures/linter"];

apps/oxlint/src/snapshots/[email protected]

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ source: apps/oxlint/src/tester.rs
55
arguments: foo.asdf
66
working directory:
77
----------
8-
Found 0 warnings and 0 errors.
9-
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
8+
Finished in <variable>ms on 0 files with 0 rules using 1 threads.
109
----------
11-
CLI result: LintSucceeded
10+
CLI result: LintNoFilesFound
1211
----------
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_file_current_dir
7+
----------
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
10+
----------
11+
CLI result: LintSucceeded
12+
----------
13+
14+
##########
15+
arguments: .
16+
working directory: fixtures/ignore_file_current_dir
17+
----------
18+
Found 0 warnings and 0 errors.
19+
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
20+
----------
21+
CLI result: LintSucceeded
22+
----------

0 commit comments

Comments
 (0)