Skip to content

fix(linter): check whether path is under root before ignoring it#20101

Merged
camc314 merged 16 commits into
oxc-project:mainfrom
Leonabcd123:fix-panic-with-ignore-patterns
May 12, 2026
Merged

fix(linter): check whether path is under root before ignoring it#20101
camc314 merged 16 commits into
oxc-project:mainfrom
Leonabcd123:fix-panic-with-ignore-patterns

Conversation

@Leonabcd123

@Leonabcd123 Leonabcd123 commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Bug Description

When ignorePatterns is set in the cwd .oxlintrc.json file, and we try to lint a file outside of the cwd, we get a panic:

thread 'tokio-runtime-worker' (171644) panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ignore-0.4.25/src/gitignore.rs:232:9:
path is expected to be under the root
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This happens because of this line:

.is_some_and(|base| base.matched_path_or_any_parents(path, false).is_ignore())

We call matched_path_or_any_parents (which can panic if path is not under root, see https://docs.rs/ignore/latest/ignore/gitignore/struct.Gitignore.html#panics).

Steps to reproduce

mkdir ~/test1
mkdir ~/test2
cd ~/test1 && echo '{ "ignorePatterns": ["node_modules"] }' > .oxlintrc.json
touch ~/test2/test.js
oxlint ~/test2

Solution

To fix this, we check whether path is under the root config's path before deciding whether to ignore it or not. If it isn't, we don't ignore it, otherwise we keep current behavior. This matches oxfmt's is_path_ignored:

pub fn is_path_ignored(&self, path: &Path, is_dir: bool) -> bool {
self.ignore_glob.as_ref().is_some_and(|glob| {
// `matched_path_or_any_parents()` panics if path is not under the glob's root.
path.starts_with(glob.path())
&& glob.matched_path_or_any_parents(path, is_dir).is_ignore()
})
}

Fixes #22269

@Leonabcd123 Leonabcd123 requested a review from camc314 as a code owner March 7, 2026 10:41
@github-actions github-actions Bot added A-linter Area - Linter C-bug Category - Bug labels Mar 7, 2026
@camc314 camc314 self-assigned this Mar 9, 2026
@codspeed-hq

codspeed-hq Bot commented Apr 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing Leonabcd123:fix-panic-with-ignore-patterns (ccf66a8) with main (41fcdcf)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Leonabcd123,

Thanks for this PR.

Could you write a failing test for this first so we can assert that the behaviour never regresses in future?

Thanks

@Leonabcd123 Leonabcd123 requested a review from camc314 April 9, 2026 16:07
@riadafridishibly

Copy link
Copy Markdown

I was about to file an issue, then I saw this PR. I hope this one gets resolved soon. Thanks.

@camchenry camchenry self-assigned this May 12, 2026

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank yoU!

@camc314 camc314 merged commit 4818d98 into oxc-project:main May 12, 2026
28 checks passed
@Leonabcd123 Leonabcd123 deleted the fix-panic-with-ignore-patterns branch May 12, 2026 18:03
overlookmotel added a commit that referenced this pull request May 15, 2026
# Oxlint
### 🚀 Features

- 5478fb5 linter/jsdoc: Implement `require-throws-description` rule
(#22386) (Mikhail Baev)
- b46d4de linter: Add `--debug` options and add per-rule timing info
(#22282) (camchenry)
- c73225e linter/eslint: Implement `prefer-arrow-callback` rule (#22312)
(박천(Cheon Park))
- de82b59 linter: Add support for `eslint-plugin-jsx-a11y-x` (#22356)
(mehm8128)
- b170da3 linter: Implement no-implicit-globals (#22249) (Jovi De
Croock)
- f44b6c8 linter: Fill schemas `DummyRuleMap` with built-in rules
(#22288) (Sysix)
- 5cdb80d linter/jsx-a11y/: Implement
no-interactive-element-to-noninteractive-role (#22332) (anarefolio)
- 2749422 linter/jsx-a11y: Add no-noninteractive-element-interactions
(#22337) (Pablo Tovar)
- ba2a1d3 linter/jsdoc: Implement `require-throws-type` rule (#22358)
(Mikhail Baev)
- d90729d linter/jsx-a11y: Implement control-has-associated-label
(#21985) (mehm8128)
- 1d04903 linter/jsdoc: Implement `require-yields-type` rule (#22331)
(Mikhail Baev)

### 🐛 Bug Fixes

- 04c4609 linter/no-nullable-type-assertion-style: Mark as suggestion
(#22450) (camc314)
- 1c2b7ec linter/no-unused-vars: Handle shadowed self assignments
(#22387) (camc314)
- 9faa1d5 linter/no-noninteractive-tabindex: Check conditional
expressions (#22435) (camc314)
- 0854b3a linter/prefer-arrow-callback: Preserve TSX generic arrows in
fixer (#22434) (camc314)
- 410b814 linter: Supply `source_type` to codegen fixer (#22433)
(camc314)
- 3c1bb6f linter: Skip per-node dispatch for run_once-only rules in
large files (#22398) (Connor Shea)
- 5206cde linter/no-unused-vars: Improve type-only rest parameters
diagnostic (#22385) (camc314)
- c9a22b5 linter/consistent-function-scoping: Allow imported bindings
(#22384) (camc314)
- c1e966d linter: Report type-only unused parameters in no-unused-vars
(#22368) (camchenry)
- 4818d98 linter: Check whether path is under root before ignoring it
(#20101) (Leonabcd123)
- 41fcdcf linter: Fix rule count not including override rules (#19898)
(Daniel Osmond)
- 59b4f0e linter: Fix 'explicit-module-boundary-types' false positive
with 'allowOverloadFunctions' (#22341) (camchenry)

### ⚡ Performance

- 6d42395 linter: Narrow no-unsafe-optional-chaining dispatch (#22437)
(camchenry)
- 08595fb linter: Optimize no-unreachable (#22397) (camchenry)
- 3b46a8d linter: Optimize `no-loss-of-precision` (#22395) (camchenry)
- b3e2dc9 linter: Optimize `oxc/bad-array-method-on-arguments` (#22393)
(camchenry)

### 📚 Documentation

- dcbf62c linter: Remove some duplicate spaces (#22359) (camc314)
# Oxfmt
### 💥 BREAKING CHANGES

- 21bb5d1 oxfmt: [**BREAKING**] Avoid config pre-scan (#22258)
(leaysgur)

### 🐛 Bug Fixes

- 441d724 oxfmt: Fix "race probe" logic with unit tests (#22378)
(leaysgur)
- e49ee26 formatter: Respect `singleQuote` for jsdoc `import()` type
paths (#22353) (Colin Lienard)
- 43b9978 formatter/sort_imports: Treat subpath imports as internal
(#22440) (leaysgur)
- 7c5cfa0 formatter: Handle jsx trailing comment with parens (#22370)
(leaysgur)
- ac5f120 formatter: Fix erroneous formatting inside a template literal
with parentheses (#22262) (Jovi De Croock)
- 3c53a95 formatter/sort_imports: Handle ignore comment as boundary
(#22369) (leaysgur)
- 4dd83dd oxfmt: Send expandedStates variants as shared refs (#22366)
(leaysgur)
- 055cc61 formatter: Expand JSX logical chain with leading line comment
(#22346) (leaysgur)
- 8046222 formatter: Preserve type alias comment break (#22261) (Jovi De
Croock)

### ⚡ Performance

- 123c493 oxfmt: Reduce more syscalls (#22380) (leaysgur)

Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: Oxlint panics when lint target is passed as an absolute path

4 participants