Repository navigation
chore(web): remove unused exports and orphan files and enforce TS export check - #1278
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a custom script (check-web-unused-exports.mjs) to detect unused or unnecessarily exported TypeScript symbols and integrates it into the frontend linter pipeline. It also cleans up the codebase by removing unused files and stripping the export modifier from numerous interfaces, functions, and classes that are only used internally. The review feedback is highly constructive, suggesting path normalization to prevent drive-letter casing issues on Windows and recommending caching of script snapshots to optimize disk I/O and improve the script's execution speed.
TypeScript Quality Report (
|
| Metric | Result |
|---|---|
| Changed Scope | 60 prod file(s), 0 test file(s), 60 unit(s) |
| Patch Coverage | 100.0% (28/28 lines) |
| Mutation Score | 100.0% (0/0 killed, 0 survived) |
Commit: 38543d62b5b2 · Cloud Build Logs
8b6112a to
35f14bd
Compare
35f14bd to
196e6aa
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a tool to detect unused exports and orphan TypeScript files in the frontend workspace, integrating it into the linting and testing pipelines. It also refactors numerous files across the codebase to remove unnecessary exports and clean up unused types, interfaces, and functions. The review feedback highlights an issue in check-unused-exports.ts where chained re-exports are not fully resolved, potentially failing to flag certain unused exports, and suggests a robust fix to track the original definition file.
78a1bec to
38543d6
Compare
Background
TypeScript's
noUnusedLocalscompiler option intentionally skips declarations marked withexportbecause another module could import them. Over time, frontend refactors leave behind orphaned.tsfiles, completely unusedexportdeclarations, and helper symbols markedexportdespite only being referenced within their own declaring file.Approach
Add
web/scripts/check-unused-exports.ts(strictly type-checked viaweb/tsconfig.scripts.json, linted viang lint, and unit-tested inweb/scripts/check-unused-exports.spec.ts) using the existingweb/node_modules/typescriptLanguage Service API (requiring zero external npm dependencies), and wire it intonpm run lint:unused,make lint-web, andmake test-web:orphan-ts-file: Flags non-generated, non-spec, non-story.tsfiles underweb/srcandweb/scriptsthat are neither entrypoints nor imported anywhere acrossweb/src,web/.storybook, andweb/scripts.unused-export: Flags exported declarations and re-exports with zero references across both their declaring file and external modules.unnecessary-export: Flagsexportmodifiers on declarations referenced only within their own declaring file.Delete existing orphaned files, remove dead exports, and drop unnecessary
exportmodifiers from file-local declarations.