Repository navigation
MAINT: Add Knip config for the frontend - #4413
Open
Abhiram Shaji (abhiramshaji-cyber) wants to merge 1 commit into
Open
Abhiram Shaji (abhiramshaji-cyber) wants to merge 1 commit into
Abhiram Shaji (abhiramshaji-cyber) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the frontend Knip configuration changes.
No open issues 🎉
What changed in this PR
Adds frontend Knip configuration to reduce false positives, supporting the entrypoint-aware cleanup planned in #3730. This is configuration only; it does not change application behavior or add CI integration.
Changes:
- Registers the Jest transformer and E2E fixture TSX files as entrypoints.
- Excludes
pythonfrom unlisted-binary reports. - Suppresses unused-export reports for types and interfaces used within their own file.
| File | Description |
|---|---|
frontend/knip.json |
Defines additional entrypoints and targeted exclusions for frontend dead-code analysis. |
Review effort: Balanced
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Running Knip on the frontend reported test helpers, fixtures and file local types as dead code, and this PR adds a config so it only reports real candidates.
What this code is for
frontend/knip.jsonis read by Knip when someone runsnpx knipinsidefrontend/. Knip walks the imports from each entry file and lists files, exports and dependencies nothing reaches. Nothing runs it in CI yet; this is the config only first step agreed in #3730, with the cleanups in a separate PR.Before this PR
A contributor runs
npx knipinfrontend/on main (b6969d6).jest-import-meta-transformer.tsby path fromastTransformers, which the Jest plugin does not follow, so Knip lists it as an unused file.e2e/fixtures/numeric-controls.tsxande2e/fixtures/editor-workspace.tsxare loaded by<script>tags in their.htmlfixtures, so both are listed as unused files too.start,restartandstopscripts callpython, listed as an unlisted binary.After this PR
Same contributor, same command.
entryaddsjest-import-meta-transformer.tsande2e/fixtures/*.tsx, so Knip sees them as used. Unused files: 0.ignoreBinariesskipspython. Unlisted binaries: 0.ignoreExportsUsedInFileskips types and interfaces used in their own file. Unused exported types: 1 (ScenarioRunEstimator).schedulerandts-nodein devDependencies,@jest/globalsunlisted, 16 exports and that one type.The diagram
flowchart LR classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827 classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px subgraph BEFORE["BEFORE: 3 files and 86 types flagged"] direction TB B1["npx knip in frontend"] --> B2["plugin entries only"] B2 --> B3["walk imports"] B3 --> B4{"no knip.json"} B4 -->|"path and script tag loads missed"| B5["helpers, fixtures, types flagged"] B4 -->|"real unused code"| B6["flagged, buried in noise"] end subgraph AFTER["AFTER: 0 files and 1 type flagged"] direction TB A1["npx knip in frontend"] --> A2["plugin entries only"] A2 --> A3["walk imports"] A3 --> A4{"THE CHANGE: knip.json entries"} A4 -->|"transformer, fixtures, file local types"| A5["not flagged"] A4 -->|"real unused code"| A6["still flagged"] end B1 ~~~ A1 class B1,B2,B3,B6 box class A1,A2,A3,A6 box class B4,B5 bad class A4,A5 good linkStyle 3 stroke:#cc0000,stroke-width:5px linkStyle 8 stroke:#008800,stroke-width:5px style BEFORE fill:#fff5f5,stroke:#cc0000,color:#111827 style AFTER fill:#f3fff3,stroke:#008800,color:#111827The change
One new file,
frontend/knip.json, exactly as posted in #3730: twoentryglobs,ignoreBinaries: ["python"]andignoreExportsUsedInFileforinterfaceandtype. No script, dependency or source change.What changes for a user
vite.config.ts, which runs Python 3.11+ for the compatibility stamp, soPYRIT_PYTHONmay need setting locally. Wiring Knip into CI is left out on purpose.Part of #3730.