Repository navigation
test(core): import scanner and reference-exclusion rule - #6
Conversation
|
| Topic | Details | ||||||
|---|---|---|---|---|---|---|---|
| Reference exclusion | Verify that reference/ remains outside ESLint, TypeScript, Vitest, and workspace processing, while preserving benchmark project isolation and testing the TypeScript matcher behavior.Modified files (1)
Latest Contributors(1)
| ||||||
| Import scanner | Implement scanSource and directory scanning to detect forbidden imports and process environment access, with fixtures covering allowed and disallowed patterns and verification against core source.Modified files (20)
Latest Contributors(1)
|
cfd3923 to
4afd561
Compare
2cd5532 to
77e3e03
Compare
🐕 Shuni ReviewAdds the core boundary scanner, its fixtures and tests, and architecture tests that keep Actionable comments posted: 0 🧹 Nitpick comments: 1 Merge risk: 🟢 Low: the change is test-only; the new gap affects only See inline comments for details. Unresolved prior findings: 1
🤖 Model: Review scope: Full review Reviewed files (21)
🐕 Review complete — View session on Shuni Portal 🐾 🤖 Model: |
77e3e03 to
fd85c87
Compare
Baz withdrew its approval because this pull request is no longer ready to merge.
fd85c87 to
df55b65
Compare
e0f1608 to
cca496c
Compare
| const rel = path.relative(dir, path.join(repoRoot, probe)).split(path.sep).join("/"); | ||
| const matches = (glob: string) => path.matchesGlob(rel, glob) || path.matchesGlob(rel, `${glob.replace(/\/$/, "")}/**`); | ||
| const excluded = (config.exclude ?? []).some(matches); | ||
| return !excluded && ((config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (config.include ?? []).some(matches)); |
There was a problem hiding this comment.
🧪 Test Reliability | 🔵 Trivial | ⚡ Quick fix
Don't let exclude cancel an explicit files entry
In TypeScript, exclude filters only what include matches; files listed in files are always compiled. Here excluded also suppresses a files match. As a result, { files: ["reference/relay/src/index.ts"], exclude: ["reference"] } returns false even though tsc would compile that file.
| return !excluded && ((config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (config.include ?? []).some(matches)); | |
| return (config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (!excluded && (config.include ?? []).some(matches)); |
There was a problem hiding this comment.
This is still open at the current head. Line 23 still applies excluded before the files check, so exclude can cancel an explicitly listed file.
| if (processNamedEnvImport.test(text)) found.push("imports env from the process module"); | ||
| for (const match of text.matchAll(processAliasImport)) { | ||
| const alias = match[1] ?? ""; | ||
| if (new RegExp(`\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick fix
Use an identifier-aware boundary instead of \b around the alias
The escape is now complete, but \b sees a boundary only between a word character and a non-word character, and $ is not a word character. For import * as $p from "node:process"; $p.env.X, the pattern \b\$p… needs a boundary between the space and $ and finds none, so the env read is not reported. An alias that ends in $ fails the same way: the capture group backtracks and returns a shorter name. A lookbehind for identifier characters handles both cases.
| if (new RegExp(`\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) { | |
| if (new RegExp(`(?<![\\w$])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) { |
What changed
The import scanner used by the architecture tests (
packages/core/test/boundaries/scan.ts, a parser-based scan for forbidden imports andprocess.envuse), its tests, and the rule that no TypeScript project includes thereference/directory (passes with that directory absent). It also brings the 17 fixture files thatscan.test.tsreads.Stacked on #4 (which is stacked on #3). Auto-merge stays off until the base has merged and this branch has been rebased onto
mainand retargeted.Why
Later slices add rules that every package must obey; the scanner is the shared tool for them.
How it was verified
npm ci --ignore-scripts, lint, typecheck, build,npm test(28 tests),npm run test:tools, gitleaks (git and dir), actionlint, zizmor: all exit 0. The diff against its base is exactly the 21 files of this slice.The fixtures were planned for the next slice, but
scan.test.tsfails without them, so they moved here.Not here yet
The adapter import rules and the lint-fixture test (next slice).
Checklist