Skip to content

MAINT: Add Knip config for the frontend - #4413

Open
Abhiram Shaji (abhiramshaji-cyber) wants to merge 1 commit into
microsoft:mainfrom
abhiramshaji-cyber:chore/frontend-knip-config
Open

Abhiram Shaji (abhiramshaji-cyber) wants to merge 1 commit into
microsoft:mainfrom
abhiramshaji-cyber:chore/frontend-knip-config

Conversation

@abhiramshaji-cyber

Copy link
Copy Markdown

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.json is read by Knip when someone runs npx knip inside frontend/. 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 knip in frontend/ on main (b6969d6).

  1. Knip starts from the entries its Jest, Vite and Playwright plugins find.
  2. ts-jest loads jest-import-meta-transformer.ts by path from astTransformers, which the Jest plugin does not follow, so Knip lists it as an unused file.
  3. e2e/fixtures/numeric-controls.tsx and e2e/fixtures/editor-workspace.tsx are loaded by <script> tags in their .html fixtures, so both are listed as unused files too.
  4. The start, restart and stop scripts call python, listed as an unlisted binary.
  5. Props and result types used only inside their own file are listed as unused exported types: 86 of them.
  6. The real findings are buried under all of that.

After this PR

Same contributor, same command.

  1. entry adds jest-import-meta-transformer.ts and e2e/fixtures/*.tsx, so Knip sees them as used. Unused files: 0.
  2. ignoreBinaries skips python. Unlisted binaries: 0.
  3. ignoreExportsUsedInFile skips types and interfaces used in their own file. Unused exported types: 1 (ScenarioRunEstimator).
  4. What is left is the cleanup list from Knip identifies potentially dead exports and shared types that need entrypoint-aware triage #3730: scheduler and ts-node in devDependencies, @jest/globals unlisted, 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:#111827
Loading

The change

One new file, frontend/knip.json, exactly as posted in #3730: two entry globs, ignoreBinaries: ["python"] and ignoreExportsUsedInFile for interface and type. No script, dependency or source change.

What changes for a user

Part of #3730.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 python from 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

No deployments
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.

2 participants