Skip to content

fix(lint): stop the plugin's paths at the drive, and resolve without the cwd - #2009

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

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

Conversation

@Luckyou-d

Copy link
Copy Markdown
Contributor

Problem

Two defects kept most of this plugin's rules from firing at all on Windows, so npm run lint there passed violations it reports everywhere else.

1. The walk up does not stop at a drive

workspaceRoot and packageRoot climb with path.posix.dirname, which answers . above a drive (C: -> .). The climb treated that . as an ancestor, read the checkout's own package.json - the one that declares workspaces - and returned ".". repositoryPath() then made every file's relative path the whole absolute one:

{"filename":"C:/…/0/src/a.ts","root":".","relative":"C:/…/0/src/a.ts"}

so each rule's scope test (src/**, packages/*/src/**) failed and the rule checked nothing. Measured with a fixture that must be flagged: oxlint returned {"diagnostics": []}.

2. path.posix.resolve consults the process directory

path.posix.resolve(dir, specifier) uses the process directory unless its first argument starts with /, and a Windows path this plugin builds (C:/checkout/src) does not:

path.posix.resolve('C:/checkout/src/__tests__', '../utils/log')
  -> '/cwd/C:/checkout/src/utils/log'      # nothing there

mock-source and package-boundaries/tool-registry looked up specifiers that never existed.

3. The harness's .bin shim needs a shell

spawnSync(OXLINT, …, { shell: process.platform === 'win32' }) is what a .cmd needs on Windows, and cmd.exe caps the command line: package-boundaries (80 fixtures) got back output that was not JSON, so its whole suite failed before any case ran.

Change

  • isWalkEnd() stops the climb at a POSIX root or a drive. . is deliberately not an end: it is the right root for a filename oxlint reports relative to its own directory, and that behaviour is unchanged.
  • resolveFrom() joins and normalizes instead of resolving against the cwd; mock-source (2 call sites), package-boundaries and tool-registry use it.
  • The harness runs node_modules/oxlint/bin/oxlint with process.execPath, no shell, on every platform.

Verification

Windows 11 / Node v24.18.0, npx vitest run oxlint-plugin-teamai:

files tests
main 12 failed / 35 passed 119 failed / 1158 passed
this branch 1 failed / 46 passed 13 failed / 1264 passed
this branch + #1967 47 passed 1277 passed

The 13 left on this branch alone are exactly the family-facts cases #1967 fixes; with it applied the suite is fully green on Windows.

  • npm run lint: 26 errors before and after - the pre-existing teamai(family-facts) ones this checkout reports on main, none new. The rules that now fire flagged two require-readable-spacing violations in my own first draft of this patch, which I fixed rather than suppressed - a small proof that they run.
  • npx tsc --noEmit clean. resolveFrom is used by four call sites; no path.posix.resolve is left in the plugin.
  • Not covered: whether isWalkEnd should also treat a UNC share (//server/share) as an end. It cannot occur here, and the walk stops at . for such a path the way it does for a relative one.

Refs #1967 (the same class, in the rules' own import resolution) and #1889.

…the cwd

Two Windows defects kept most of this plugin's rules from firing at all, so
`npm run lint` passed violations it reports on every other platform.

`workspaceRoot` and `packageRoot` walk up with `path.posix.dirname`, which
answers `.` above a drive: `C:` -> `.`. The walk treated that `.` as an
ancestor, read the checkout's own package.json - the one declaring
`workspaces` - and returned `"."`, so `repositoryPath()` made every file's
relative path the whole absolute one and each rule's scope test failed. On
Windows, 12 of the rules silently checked nothing.

`path.posix.resolve(dir, specifier)` consults the process directory unless its
first argument starts with `/`, and a Windows path this plugin builds
(`C:/checkout/src`) does not: `mock-source` resolving `../utils/log` against it
produced `/cwd/C:/checkout/src/utils/log`, so the specifier it looked up never
existed. `resolveFrom()` joins and normalizes instead, and the four call sites
use it.

The test harness spawned the `.bin` shim with `shell: true`, which is what a
`.cmd` needs on Windows: cmd.exe caps the command line, so a rule with many
fixtures got back output that was not JSON and its whole suite failed. It now
runs the package's own entry with this Node, no shell.

With Tencent#1967 in, the suite is 1277/1277 on Windows; on this branch alone 119
failures drop to the 13 that Tencent#1967 fixes.

@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 PR appears to overlap substantially with #1935, #1944, and #1947:

  • #1935 addresses mock-source path resolution on Windows.
  • #1944 runs oxlint without the Windows shell.
  • #1947 stops workspace discovery at the drive root.

This PR appears to combine all three areas under one path-handling approach. Could a maintainer confirm which implementation should be kept, and whether the focused regression tests from the older PRs should be carried into this one?

@Luckyou-d

Copy link
Copy Markdown
Contributor Author

You are right that this overlaps #1935, #1944 and #1947, and it does cover all three. The reason it is one diff rather than three is that they share a root cause the focused fixes do not reach:

workspaceRoot/packageRoot in oxlint-plugin-teamai/utils.js climbed out of the workspace with path.posix.resolve, which returns "." once the path crosses the Windows drive root (C:\). Every rule then compared a relative path against ".", matched nothing, and 12 rules silently never fired on Windows - mock-source, package-boundaries, tool-registry and the rest are all downstream of that one value. So:

Evidence, on Windows: the plugin's own suite goes from 119 failing to 13 failing on its own, and to 1277 passing with #1967 applied. That is the number that shows the rules actually run now; #1947's focused test only covers the stop at the root.

If you would rather land the three focused diffs first, say so and I will close this and re-open only the utils.js root-cause part. I am not attached to the combined shape - I just did not want to send four PRs for one bug.

@github-actions

Copy link
Copy Markdown
  • [P3 nit] Check the terminal directory’s manifest before stopping — oxlint-plugin-teamai/utils.js:126: For a workspace rooted at / or C:/, the new early return skips its package.json. For example, workspaceRoot('/src') no longer discovers /package.json declaring workspaces, so repository-scoped rules can miss that workspace. packageRoot has the same regression. Check the terminal directory before stopping further traversal.

The description documents Windows lint and plugin-test runs sufficiently for this lint-rule-only change; no real-CLI verification record is required. I did not run, build, or install PR code.

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