fix(oxlint): normalize explicit --config paths so overrides resolve from the config dir#21027
fix(oxlint): normalize explicit --config paths so overrides resolve from the config dir#21027niieani wants to merge 1 commit intooxc-project:mainfrom
Conversation
…rom the config dir
camc314
left a comment
There was a problem hiding this comment.
What is the use case for having your config outside of the directory your linting - surely you're going to end up with really wierd ignore patterns behaviour.
@camc314 Hi Cameron, thanks for taking a look. This is to enable partial linting from a subdirectory - a monorepo for example. You're inside of a single package, and only want to lint that package. Right now this is broken in oxlint, because the rules resolve correctly only when in the root directory of the repository. That's a pretty substantial assumption. Both of these should be equivalent, but currently running the 2nd one applies relative paths from the current directory, rather than the directory of the config file. |
Summary
This fixes a path-resolution bug in
oxlintwhen an explicit config is passed from a nested working directory, for example:cd files oxlint -c ../oxlint.config.ts filesIn that case, the explicit config path was made absolute but not lexically normalized, so it could still contain
..segments. That broke later override matching, because override globs are resolved relative to the config file’s parent directory. If the stored config path was something like/repo/foo/files/../oxlint.config.ts, then matching a lint target like/repo/foo/files/test.jsagainst the config parent would fail lexically, and overrides such asfiles/**/*.jswould not apply.In practice, this caused rules configured through overrides to silently not fire, which can also surface as misleading
unused eslint-disablediagnostics.What This Changes
--configpaths lexically inConfigLoaderbefore loading them.cwd, but ensure the stored path no longer contains.or..components.oxlintfrom a nestedcwd-c ../oxlint.config.tsfiles/**/*.jsWhy This Is Correct
The bug was not in override logic itself, but in the shape of the path data fed into it.
Override application later does path matching relative to
config.path.parent(). That logic assumes the config path and lint target path are in the same normalized path form. If the config path retains..segments while the lint target path does not,strip_prefixfails even though both paths refer to the same real location.Lexically normalizing the explicit config path at load time fixes that mismatch at the source:
cwdThis is also the right scope for the fix: explicit config loading is where the inconsistent path form was introduced.
User-Facing Effect
This fixes cases where running
oxlintfrom a subdirectory with an explicit config path causes override-based rules to stop applying. After this change, those overrides apply correctly, and downstream diagnostics such asunused eslint-disableare no longer produced spuriously because the intended rules now run.Tests
cwd+ explicit-config override case../..components.AI Usage
Used
codexto help with creating this PR.