Repository navigation
chore(knip): add lint:knip:production check to report code only used by tests (AI-assisted) - #12761
Merged
Merged
Conversation
…ma (AI-assisted) DEFAULT_OPTIONS was only used by tests. Using it in the schema, like the other plugins do, keeps the tested defaults and the real defaults in sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(AI-assisted) - plugin-svgr: @svgr/core is only used by tests (@svgr/webpack depends on it) - theme-classic: react-router-dom is only used by tests, theme components use @docusaurus/router Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…by tests (AI-assisted) Knip production mode ignores the tests, so it reports the exports and dependencies of published packages that only tests use. Exports also used in their own file are not reported: functions are often exported only to be tested. Hand-written Knip entries need a trailing "!" to be production entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: 0 B Total Size: 12.1 MB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 12.1 MB ℹ️ View Unchanged
|
⚡️ Lighthouse report for the deploy preview of this PR
|
slorber
commented
Oct 23, 2026
| }, | ||
| "devDependencies": { | ||
| "@docusaurus/module-type-aliases": "workspace:*", | ||
| "@svgr/core": "catalog:dev", |
Collaborator
Author
There was a problem hiding this comment.
note: @svgr/webpack already depends on @svgr/core so that's ok
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.
Motivation
Inspired by TkDodo's talk Dead code shouldn't exist: Knip's production mode ignores the tests, so combined with
ignoreExportsUsedInFileit finds the code that only tests keep alive.This PR adds a
pnpm lint:knip:productioncheck, run in CI and bypnpm lint:knip --production --exports --dependencies --no-tag-hints --workspace './packages/*'It reports the exports and dependencies of our published packages that only tests use:
--workspace './packages/*': only the published packages. Unscoped, production mode reports the dev scripts, test helpers and website config as unused. The./matters:'packages/*'silently matches nothing. It also excludes the nestedcreate-docusaurussite templates.--exports --dependencies: only these issue types, production mode reports the test helpers as unused files.--no-tag-hints: silences the hints about theme-common's@internalJSDoc tags, which document internal APIs.ignoreExportsUsedInFile, only in production mode: exports also used in their own file are not reported, they are often exported only to be tested. The Knip config becomes a function to read theproductionCLI arg.main/exports/binfields are production entries, but the entries ofknip.config.tsneed a trailing!.The check needs the 2 first commits, which fix what it reports on
main:DEFAULT_OPTIONSwas only used by tests. The options schema now uses it, keeping the tested defaults and the real defaults in sync.@svgr/core(plugin-svgr) andreact-router-dom(theme-classic) were only imported by tests: moved todevDependencies, and@svgr/coreto the dev catalog. Sites still get them through@svgr/webpackand@docusaurus/core.Known blind spot: the docs, blog, live-codeblock and mermaid packages export
./lib/*and./src/*, so all their files are entries and their unused exports are never reported.Test Plan
pnpm lint:knipandpnpm lint:knip:productionpass, CI runs the new check.docusaurus-utils/src/urlUtils.tsand a test-only dependency indocusaurus-utils: the new check reports both,lint:knipdoesn't.Test links
Deploy preview: https://deploy-preview-12761--docusaurus-2.netlify.app/
Related issues/PRs
Extracted from the dead code sweep validated in draft #12751.
(AI-assisted)
🤖 Generated with Claude Code
Summary by CodeRabbit