-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix clippy, rustfmt, Miri, and stale tsconfig references on main #37078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a50739a
Fix clippy, rustfmt, and stale tsconfig references on main
robobun 1cdbe8b
Add a source lint asserting tsconfig project references resolve
robobun 53f6080
Harden the tsconfig-references lint's JSONC handling
robobun d70c236
Remove the tsconfig-references source lint
robobun d0fec75
highway: take the scalar path under Miri instead of calling the C++ k…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Every `references[].path` reachable from the repo root tsconfig.json must | ||
| // resolve to a real project: a tsconfig file, or a directory containing a | ||
| // tsconfig.json (the two shapes tsc accepts). A stale path, left behind when | ||
| // a project directory moves, fails `tsc --noEmit` at the root with TS6053 | ||
| // before checking anything, and breaks editor language service features for | ||
| // the whole solution. src/bake -> src/runtime/bake was caught by hand; this | ||
| // keeps the graph honest mechanically. | ||
|
|
||
| import { expect, test } from "bun:test"; | ||
| import { statSync } from "fs"; | ||
| import path from "path"; | ||
|
|
||
| const root = path.resolve(import.meta.dir, "..", "..", ".."); | ||
|
|
||
| // tsconfig.json is JSONC: strip // and /* */ comments (string-aware) and | ||
| // trailing commas, then JSON.parse. A malformed file throws, failing the test | ||
| // with the offending path in the message. | ||
| function parseJsonc(text: string, from: string): any { | ||
| let out = ""; | ||
| let i = 0; | ||
| let inString = false; | ||
| while (i < text.length) { | ||
| const c = text[i]; | ||
| if (inString) { | ||
| out += c; | ||
| if (c === "\\") { | ||
| out += text[i + 1] ?? ""; | ||
| i += 2; | ||
| continue; | ||
| } | ||
| if (c === '"') inString = false; | ||
| i++; | ||
| continue; | ||
| } | ||
| if (c === '"') { | ||
| inString = true; | ||
| out += c; | ||
| i++; | ||
| continue; | ||
| } | ||
| if (c === "/" && text[i + 1] === "/") { | ||
| while (i < text.length && text[i] !== "\n") i++; | ||
| continue; | ||
| } | ||
| if (c === "/" && text[i + 1] === "*") { | ||
| i += 2; | ||
| while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++; | ||
| i += 2; | ||
| continue; | ||
| } | ||
| out += c; | ||
| i++; | ||
| } | ||
| try { | ||
| return JSON.parse(out.replace(/,\s*([}\]])/g, "$1")); | ||
| } catch (e) { | ||
| throw new Error(`failed to parse ${from}: ${e}`); | ||
| } | ||
| } | ||
|
|
||
| // tsc's resolution for a reference path: a file is used as-is, a directory | ||
| // means <dir>/tsconfig.json. | ||
| function resolveReference(fromDir: string, ref: string): string | null { | ||
| const p = path.resolve(fromDir, ref); | ||
| const stat = (() => { | ||
| try { | ||
| return statSync(p); | ||
| } catch { | ||
| return null; | ||
| } | ||
| })(); | ||
| if (stat?.isFile()) return p; | ||
| if (stat?.isDirectory()) { | ||
| try { | ||
| if (statSync(path.join(p, "tsconfig.json")).isFile()) return path.join(p, "tsconfig.json"); | ||
| } catch {} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
| return null; | ||
| } | ||
|
|
||
| test("tsconfig project references resolve", async () => { | ||
| const missing: string[] = []; | ||
| const visited = new Set<string>(); | ||
| const queue = [path.join(root, "tsconfig.json")]; | ||
| while (queue.length > 0) { | ||
| const cfgPath = queue.pop()!; | ||
| if (visited.has(cfgPath)) continue; | ||
| visited.add(cfgPath); | ||
| const cfg = parseJsonc(await Bun.file(cfgPath).text(), path.relative(root, cfgPath)); | ||
| for (const ref of cfg.references ?? []) { | ||
| const resolved = resolveReference(path.dirname(cfgPath), ref.path); | ||
| if (resolved === null) { | ||
| missing.push(`${path.relative(root, cfgPath)} references "${ref.path}", which does not exist`); | ||
| } else { | ||
| queue.push(resolved); | ||
| } | ||
| } | ||
| } | ||
| expect(missing).toEqual([]); | ||
| // The root is a solution file; reaching only it means the walk went wrong. | ||
| expect(visited.size).toBeGreaterThan(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.