Skip to content

Commit

Permalink
fix(oxlint): canonicalize paths provided as args
Browse files Browse the repository at this point in the history
  • Loading branch information
BenShelton committed Feb 28, 2025
1 parent 23480e6 commit e451332
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/ignore_file_current_dir/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ignorePatterns": [
"foo.js",
"a/bar.js"
],
"rules": {
"no-debugger": "deny"
}
}

2 changes: 2 additions & 0 deletions apps/oxlint/fixtures/ignore_file_current_dir/a/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
debugger
console.log("Don't lint me!!")
2 changes: 2 additions & 0 deletions apps/oxlint/fixtures/ignore_file_current_dir/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
debugger
console.log("Don't lint me!!")
16 changes: 14 additions & 2 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ impl Runner for LintRunner {
let (ignore, _err) = Gitignore::new(&ignore_options.ignore_path);

paths.retain_mut(|p| {
// Append cwd to all paths
let mut path = self.cwd.join(&p);
// Try to prepend cwd to all paths
let Ok(mut path) = self.cwd.join(&p).canonicalize() else {
return false;
};

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

Expand Down Expand Up @@ -580,6 +582,16 @@ mod test {
Tester::new().test_and_snapshot(args);
}

#[test]
// https://github.com/oxc-project/oxc/issues/9023
fn ignore_file_current_dir() {
let args1 = &[];
let args2 = &["."];
Tester::new()
.with_cwd("fixtures/ignore_file_current_dir".into())
.test_and_snapshot_multiple(&[args1, args2]);
}

#[test]
fn filter_allow_all() {
let args = &["-A", "all", "fixtures/linter"];
Expand Down
5 changes: 2 additions & 3 deletions apps/oxlint/src/snapshots/_foo.asdf@oxlint.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ source: apps/oxlint/src/tester.rs
arguments: foo.asdf
working directory:
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
Finished in <variable>ms on 0 files with 0 rules using 1 threads.
----------
CLI result: LintSucceeded
CLI result: LintNoFilesFound
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments:
working directory: fixtures/ignore_file_current_dir
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
----------
CLI result: LintSucceeded
----------

##########
arguments: .
working directory: fixtures/ignore_file_current_dir
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 0 files with 100 rules using 1 threads.
----------
CLI result: LintSucceeded
----------

0 comments on commit e451332

Please sign in to comment.