Skip to content

Commit 9761e94

Browse files
authored
fix(apps/oxlint): incorrect matching in .oxlintignore (#7566)
The issue was discovered while updating test cases in `rolldown`. In the `.oxlintignore` file, we have: ```ignore tests/** ``` When running the command by `lint-staged`: ```bash oxlint -c .oxlintrc.json --ignore-path=.oxlintignore --deny-warnings "tests/function/main.js" ``` The file `main.js` gets linted despite being ignored. This happens because, before using `Gitignore::new`, we converted paths to absolute paths, causing the pattern `tests/**` to not match `D:/rolldown/tests/function/main.js` correctly. https://github.com/oxc-project/oxc/blob/c61a383e8cc453fb92f85e6047426a86e50daba7/apps/oxlint/src/lint.rs#L60-L78
1 parent e62153b commit 9761e94

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123 == NaN;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123 == NaN;

apps/oxlint/src/lint.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ impl Runner for LintRunner {
5757
let provided_path_count = paths.len();
5858
let now = Instant::now();
5959

60-
// append cwd to all paths
61-
paths = paths
62-
.into_iter()
63-
.map(|x| {
64-
let mut path_with_cwd = self.cwd.clone();
65-
path_with_cwd.push(x);
66-
path_with_cwd
67-
})
68-
.collect();
69-
7060
// The ignore crate whitelists explicit paths, but priority
7161
// should be given to the ignore file. Many users lint
7262
// automatically and pass a list of changed files explicitly.
@@ -77,6 +67,16 @@ impl Runner for LintRunner {
7767
paths.retain(|p| if p.is_dir() { true } else { !ignore.matched(p, false).is_ignore() });
7868
}
7969

70+
// Append cwd to all paths
71+
paths = paths
72+
.into_iter()
73+
.map(|x| {
74+
let mut path_with_cwd = self.cwd.clone();
75+
path_with_cwd.push(x);
76+
path_with_cwd
77+
})
78+
.collect();
79+
8080
if paths.is_empty() {
8181
// If explicit paths were provided, but all have been
8282
// filtered, return early.
@@ -777,4 +777,19 @@ mod test {
777777
]);
778778
assert_eq!(result.number_of_files, 1);
779779
}
780+
781+
// Issue: <https://github.com/oxc-project/oxc/pull/7566>
782+
#[test]
783+
fn ignore_path_with_relative_files() {
784+
let args = &[
785+
"--ignore-path",
786+
"fixtures/issue_7566/.oxlintignore",
787+
"fixtures/issue_7566/tests/main.js",
788+
"fixtures/issue_7566/tests/function/main.js",
789+
];
790+
let result = test(args);
791+
assert_eq!(result.number_of_files, 0);
792+
assert_eq!(result.number_of_warnings, 0);
793+
assert_eq!(result.number_of_errors, 0);
794+
}
780795
}

0 commit comments

Comments
 (0)