Skip to content

Commit 9a02066

Browse files
authored
fix(oxlint): current dir as arg (#9382)
closes #9023 When passing `.` as an arg it would result in a path like `{cwd}/.`, which when being used to resolve other paths obviously caused issues. This canonicalizes any path args before doing anything else. Adds test to verify this based on original issue. This also caused another snapshot to change for an invalid file extension, changing from `LintSucceeded` to `LintNoFilesFound`, which I believe is actually correct? If you only pass files that do not exist it would make more sense to return an error to me so I'm viewing this as a side effect fix.
1 parent f6c6969 commit 9a02066

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed
Lines changed: 10 additions & 0 deletions
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+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
debugger
2+
console.log("Don't lint me!!")
Lines changed: 2 additions & 0 deletions
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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ impl Runner for LintRunner {
122122
let (ignore, _err) = Gitignore::new(&ignore_options.ignore_path);
123123

124124
paths.retain_mut(|p| {
125-
// Append cwd to all paths
126-
let mut path = self.cwd.join(&p);
125+
// Try to prepend cwd to all paths
126+
let Ok(mut path) = absolute(self.cwd.join(&p)) else {
127+
return false;
128+
};
127129

128130
std::mem::swap(p, &mut path);
129131

@@ -631,6 +633,16 @@ mod test {
631633
Tester::new().test_and_snapshot(args);
632634
}
633635

636+
#[test]
637+
// https://github.com/oxc-project/oxc/issues/9023
638+
fn ignore_file_current_dir() {
639+
let args1 = &[];
640+
let args2 = &["."];
641+
Tester::new()
642+
.with_cwd("fixtures/ignore_file_current_dir".into())
643+
.test_and_snapshot_multiple(&[args1, args2]);
644+
}
645+
634646
#[test]
635647
fn filter_allow_all() {
636648
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_file_current_dir
7+
----------
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 0 files with 99 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 99 rules using 1 threads.
20+
----------
21+
CLI result: LintSucceeded
22+
----------

0 commit comments

Comments
 (0)