Skip to content

chore: integrate knip and remove unused code, exports and dependencies - #22589

Closed
ulrichstark wants to merge 4 commits into
vitejs:mainfrom
ulrichstark:chore--integrate-knip-and-remove-unused-code,-exports-and-dependencies
Closed

ulrichstark wants to merge 4 commits into
vitejs:mainfrom
ulrichstark:chore--integrate-knip-and-remove-unused-code,-exports-and-dependencies

Conversation

@ulrichstark

Copy link
Copy Markdown
Contributor

Motivation

I attempted to integrate Knip into this project to automatically find and remove unused code, exports and dependencies. This PR is the result of this experiment. The knip config file is probably not optimal and I'm not sure if some removed exports might break the public API surface of vite, but nonetheless most findings are probably valuable.

Reproduce

To reproduce my changes, create the knip config of this PR and run following commands:

npx knip --fix --allow-remove-files
pnpm install
pnpm lint

Findings

  • Uninstalled unused dependencies @types/express and vue-tsc from docs/package.json
  • Deleted unused Vue component file SponsorBanner.vue from docs/.vitepress/theme/components
  • Removed a lot of unused exports
  • After removing the export keyword some members were completely unused like the esbuildPlugin function

Testing

Running pnpm test is still succeeds for me locally.

Proposed follow up changes

Maybe add knip as devDependency and run it in CI.

@sapphi-red sapphi-red added the p1-chore Doesn't change code behavior (priority) label Jun 3, 2026
@ulrichstark

Copy link
Copy Markdown
Contributor Author

I don't know why but I suddenly got these seemingly unrelated linting issues and fixed them in my previous commit:

/Users/uli/Desktop/vite/packages/vite/src/node/plugins/css.ts
  2008:41  error  Capturing group number 1 is defined but never used  regexp/no-unused-capturing-group
  2008:45  error  Capturing group number 2 is defined but never used  regexp/no-unused-capturing-group
  2010:24  error  Capturing group number 1 is defined but never used  regexp/no-unused-capturing-group

This reverts commit ab82cd4.
@ulrichstark

Copy link
Copy Markdown
Contributor Author

Tests in CI failed after I applied the lint suggestions. Just reverted that commit.

@ulrichstark

Copy link
Copy Markdown
Contributor Author

I'm closing this PR by splitting it up into #23381 and #23382.

@ulrichstark
ulrichstark deleted the chore--integrate-knip-and-remove-unused-code,-exports-and-dependencies branch August 26, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p1-chore Doesn't change code behavior (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants