Skip to content

fix(lint): resolve the plugin's rule scopes with / on every platform - #1967

Open
Luckyou-d wants to merge 1 commit into
Tencent:mainfrom
Luckyou-d:fix/lint-plugin-relative-paths
Open

Luckyou-d wants to merge 1 commit into
Tencent:mainfrom
Luckyou-d:fix/lint-plugin-relative-paths

Conversation

@Luckyou-d

Copy link
Copy Markdown
Contributor

Problem

lintedPath normalizes the linted file to /, but a path the plugin resolves itself does not:

  • sourceImport returns path.resolve's separators, so on Windows it is D:\...\src\index.ts;
  • startupEntries(root) took its root as given, so a caller passing a native path (startupEntries(REPO) in the test, path.resolve in a caller) hands it a Windows path too.

path.posix.relative on two such strings does not answer with the relative path - it names the whole absolute one:

path.posix.relative('D:\a\teamai', 'D:\a\teamai\src\x.ts')  // '../D:\a\teamai\src\x.ts'

Every rule that compares a resolved import with the repository root therefore sees a path that matches nothing.

What it breaks on Windows

npm run lint on an unmodified checkout fails with 26 teamai(family-facts) errors on the repository's own facts modules, and family-facts.test.ts fails 13 of its 35 cases - including finds the startup entries from the executables, the CLI and its hook and pull commands, which is the check that would catch it. startupsOf cannot see tsup.config.ts through the mixed path, throws declares no hook-dispatch command, and oxlint reports the throw as an error on whichever file it was linting.

Measured here (Windows 11, Node v24.18.0):

oxlint-plugin-teamai family-facts.test.ts
main 119 failed 13 failed / 22 passed
this branch 106 failed 35 passed

The remaining failures are other Windows-only assumptions in this suite, outside this change.

Change

  • toPosix() in utils.js, which lintedPath now uses (no behaviour change there);
  • sourceImport answers with / separators;
  • startupsOf normalizes the root it is given before using it.

No rule's logic changes, and POSIX platforms are unaffected: split('\').join('/') is the identity there.

Verification

  • npx vitest run oxlint-plugin-teamai/rules/family-facts.test.ts -> 35 passed (13 of them failed before)
  • npx vitest run oxlint-plugin-teamai -> 106 failed from 119, no new failure; the drop is exactly the 13 in family-facts.test.ts
  • npm run lint -> no oxlint-plugin-teamai/* error (26 before, on the repository's own packages/tool-*/src/facts.ts)
  • npx tsc --noEmit clean
  • No real-CLI record needed: oxlint-plugin-teamai is lint tooling, not runtime code.

Refs #1889 (the Windows half of the repository checks it reports; the docs and test-list halves there are separate).

`lintedPath` normalizes the linted file to `/`, but a path the plugin resolves
itself does not: `sourceImport` answers with `path.resolve`'s separators, and
`startupEntries` took its root as given. `path.posix.relative` on a Windows path
then names the whole absolute one (`../D:\...\src\index.ts`) instead of the
relative path, so every rule that compares a resolved import with the
repository root saw a path that matches nothing.

On Windows that made 13 checks in `family-facts.test.ts` fail, and `npm run
lint` reported the checkout's own facts modules as importing behaviour, because
`startupsOf` could not see `tsup.config.ts` and threw.

Normalize at the two points that produce a path, as `lintedPath` already did.

Fixes the Windows half of the repository checks reported in Tencent#1889.
@Luckyou-d

Copy link
Copy Markdown
Contributor Author

Companion to this one: #2009 fixes the same class of Windows path defect in the places this PR's normalization does not reach - the walk up stops at a drive, and specifiers resolve without consulting the cwd. With both applied npx vitest run oxlint-plugin-teamai is 1277/1277 on Windows (this PR alone leaves 13, all family-facts).

@XY-code1 XY-code1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This appears to overlap with #1927 around Windows path normalization in family-facts.js. The two PRs normalize paths at different layers (sourceImport/shared helpers versus local repoRelative handling).

Could a maintainer confirm which normalization boundary is preferred, and whether the regression cases from the other PR should be retained?

@Luckyou-d

Copy link
Copy Markdown
Contributor Author

Fair question. Here is the overlap precisely, so a maintainer can decide with the diffs in front of them.

#1927 (embrace897) changes one file: oxlint-plugin-teamai/rules/family-facts.js (+8/-3), normalising the import target it looks up.

This PR changes three, and the normalisation sits one layer below the rule:

  • oxlint-plugin-teamai/utils.js - a shared helper that resolves a path relative to the workspace with / on every platform (+12)
  • oxlint-plugin-teamai/imports.js - the import target it hands to rules goes through that helper (+10/-2)
  • oxlint-plugin-teamai/rules/family-facts.js - the local repoRelative handling is replaced by the shared helper (+3/-2)

Measured with the repo's own family-facts suite on Windows: 13/35 passing before, 35/35 after, and the family-facts lint baseline in npm run lint drops from 26 errors to 0.

So: #1927 fixes the symptom in the one rule; this one puts the normalisation in the layer both rules read. If you would rather keep the focused fix, I can close this and carry only the imports.js half (the part #1927 does not touch) into a smaller PR - your call, no argument from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants