knip 0.0.0-pep.2 → 0.0.0-plugins.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (351) hide show
  1. package/README.md +7 -917
  2. package/bin/knip.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +99 -15
  4. package/dist/ConfigurationChief.js +187 -104
  5. package/dist/ConfigurationValidator.d.ts +1092 -356
  6. package/dist/ConfigurationValidator.js +23 -7
  7. package/dist/DependencyDeputy.d.ts +29 -25
  8. package/dist/DependencyDeputy.js +123 -54
  9. package/dist/IssueCollector.d.ts +9 -1
  10. package/dist/IssueCollector.js +27 -11
  11. package/dist/IssueFixer.d.ts +21 -0
  12. package/dist/IssueFixer.js +74 -0
  13. package/dist/PrincipalFactory.d.ts +6 -3
  14. package/dist/PrincipalFactory.js +23 -10
  15. package/dist/ProjectPrincipal.d.ts +30 -25
  16. package/dist/ProjectPrincipal.js +64 -61
  17. package/dist/WorkspaceWorker.d.ts +16 -24
  18. package/dist/WorkspaceWorker.js +96 -92
  19. package/dist/binaries/bash-parser.d.ts +2 -6
  20. package/dist/binaries/bash-parser.js +9 -8
  21. package/dist/binaries/index.js +17 -7
  22. package/dist/binaries/resolvers/bun.d.ts +2 -0
  23. package/dist/binaries/resolvers/bun.js +16 -0
  24. package/dist/binaries/resolvers/fallback.js +4 -2
  25. package/dist/binaries/resolvers/index.d.ts +15 -9
  26. package/dist/binaries/resolvers/index.js +26 -9
  27. package/dist/binaries/resolvers/node.js +1 -1
  28. package/dist/binaries/resolvers/npx.js +4 -5
  29. package/dist/binaries/resolvers/pnpm.js +6 -4
  30. package/dist/binaries/resolvers/ts-node.d.ts +2 -0
  31. package/dist/binaries/resolvers/ts-node.js +16 -0
  32. package/dist/binaries/resolvers/tsx.d.ts +2 -0
  33. package/dist/binaries/resolvers/tsx.js +6 -0
  34. package/dist/binaries/resolvers/yarn.js +3 -4
  35. package/dist/binaries/types.d.ts +7 -11
  36. package/dist/cli.d.ts +0 -1
  37. package/dist/cli.js +17 -11
  38. package/dist/compilers/astro.d.ts +6 -0
  39. package/dist/compilers/astro.js +4 -0
  40. package/dist/compilers/compilers.d.ts +4 -0
  41. package/dist/compilers/compilers.js +13 -0
  42. package/dist/{util/compilers.d.ts → compilers/index.d.ts} +227 -91
  43. package/dist/compilers/index.js +46 -0
  44. package/dist/compilers/mdx.d.ts +6 -0
  45. package/dist/compilers/mdx.js +4 -0
  46. package/dist/compilers/svelte.d.ts +6 -0
  47. package/dist/compilers/svelte.js +4 -0
  48. package/dist/{types/compilers.d.ts → compilers/types.d.ts} +1 -0
  49. package/dist/compilers/vue.d.ts +6 -0
  50. package/dist/compilers/vue.js +4 -0
  51. package/dist/constants.d.ts +5 -3
  52. package/dist/constants.js +31 -14
  53. package/dist/index.js +316 -143
  54. package/dist/manifest/helpers.d.ts +8 -2
  55. package/dist/manifest/helpers.js +14 -1
  56. package/dist/manifest/index.d.ts +3 -8
  57. package/dist/manifest/index.js +12 -23
  58. package/dist/plugins/_template/index.d.ts +13 -9
  59. package/dist/plugins/_template/index.js +19 -13
  60. package/dist/plugins/_template/types.d.ts +1 -0
  61. package/dist/plugins/angular/index.d.ts +11 -6
  62. package/dist/plugins/angular/index.js +23 -21
  63. package/dist/plugins/astro/index.d.ts +10 -0
  64. package/dist/plugins/astro/index.js +24 -0
  65. package/dist/plugins/ava/index.d.ts +12 -7
  66. package/dist/plugins/ava/index.js +36 -33
  67. package/dist/plugins/ava/types.d.ts +4 -1
  68. package/dist/plugins/babel/helpers.d.ts +1 -2
  69. package/dist/plugins/babel/helpers.js +28 -20
  70. package/dist/plugins/babel/index.d.ts +10 -7
  71. package/dist/plugins/babel/index.js +22 -26
  72. package/dist/plugins/capacitor/index.d.ts +10 -6
  73. package/dist/plugins/capacitor/index.js +13 -11
  74. package/dist/plugins/changesets/index.d.ts +10 -6
  75. package/dist/plugins/changesets/index.js +13 -11
  76. package/dist/plugins/changesets/types.d.ts +3 -0
  77. package/dist/plugins/commitizen/index.d.ts +11 -7
  78. package/dist/plugins/commitizen/index.js +16 -16
  79. package/dist/plugins/commitizen/types.d.ts +1 -1
  80. package/dist/plugins/commitlint/index.d.ts +12 -6
  81. package/dist/plugins/commitlint/index.js +14 -14
  82. package/dist/plugins/cspell/index.d.ts +10 -6
  83. package/dist/plugins/cspell/index.js +15 -14
  84. package/dist/plugins/cspell/types.d.ts +1 -1
  85. package/dist/plugins/cypress/index.d.ts +10 -6
  86. package/dist/plugins/cypress/index.js +19 -11
  87. package/dist/plugins/drizzle/index.d.ts +10 -6
  88. package/dist/plugins/drizzle/index.js +16 -12
  89. package/dist/plugins/eleventy/helpers.d.ts +139 -0
  90. package/dist/plugins/eleventy/helpers.js +156 -0
  91. package/dist/plugins/eleventy/index.d.ts +14 -0
  92. package/dist/plugins/eleventy/index.js +57 -0
  93. package/dist/plugins/eleventy/types.d.ts +10 -0
  94. package/dist/plugins/eleventy/types.js +1 -0
  95. package/dist/plugins/eslint/helpers.d.ts +2 -11
  96. package/dist/plugins/eslint/helpers.js +43 -41
  97. package/dist/plugins/eslint/index.d.ts +13 -8
  98. package/dist/plugins/eslint/index.js +18 -13
  99. package/dist/plugins/eslint/types.d.ts +1 -0
  100. package/dist/plugins/gatsby/index.d.ts +11 -7
  101. package/dist/plugins/gatsby/index.js +21 -18
  102. package/dist/plugins/github-actions/index.d.ts +9 -6
  103. package/dist/plugins/github-actions/index.js +27 -22
  104. package/dist/plugins/graphql-codegen/index.d.ts +11 -0
  105. package/dist/plugins/graphql-codegen/index.js +44 -0
  106. package/dist/plugins/graphql-codegen/types.d.ts +25 -0
  107. package/dist/plugins/graphql-codegen/types.js +3 -0
  108. package/dist/plugins/husky/index.d.ts +9 -6
  109. package/dist/plugins/husky/index.js +16 -18
  110. package/dist/plugins/index.d.ts +55 -44
  111. package/dist/plugins/index.js +55 -44
  112. package/dist/plugins/jest/index.d.ts +12 -7
  113. package/dist/plugins/jest/index.js +57 -30
  114. package/dist/plugins/jest/types.d.ts +3 -0
  115. package/dist/plugins/jest/types.js +1 -0
  116. package/dist/plugins/lefthook/index.d.ts +9 -6
  117. package/dist/plugins/lefthook/index.js +26 -22
  118. package/dist/plugins/lint-staged/index.d.ts +11 -7
  119. package/dist/plugins/lint-staged/index.js +18 -20
  120. package/dist/plugins/linthtml/index.d.ts +11 -0
  121. package/dist/plugins/linthtml/index.js +23 -0
  122. package/dist/plugins/linthtml/types.d.ts +4 -0
  123. package/dist/plugins/linthtml/types.js +1 -0
  124. package/dist/plugins/markdownlint/index.d.ts +10 -6
  125. package/dist/plugins/markdownlint/index.js +15 -12
  126. package/dist/plugins/mocha/index.d.ts +12 -7
  127. package/dist/plugins/mocha/index.js +23 -18
  128. package/dist/plugins/mocha/types.d.ts +4 -0
  129. package/dist/plugins/mocha/types.js +1 -0
  130. package/dist/plugins/netlify/helpers.d.ts +2 -0
  131. package/dist/plugins/netlify/helpers.js +4 -0
  132. package/dist/plugins/netlify/index.d.ts +12 -0
  133. package/dist/plugins/netlify/index.js +34 -0
  134. package/dist/plugins/netlify/types.d.ts +11 -0
  135. package/dist/plugins/netlify/types.js +1 -0
  136. package/dist/plugins/next/index.d.ts +9 -7
  137. package/dist/plugins/next/index.js +18 -14
  138. package/dist/plugins/node-test-runner/index.d.ts +8 -6
  139. package/dist/plugins/node-test-runner/index.js +9 -16
  140. package/dist/plugins/npm-package-json-lint/index.d.ts +11 -7
  141. package/dist/plugins/npm-package-json-lint/index.js +16 -15
  142. package/dist/plugins/nx/index.d.ts +10 -6
  143. package/dist/plugins/nx/index.js +45 -21
  144. package/dist/plugins/nx/types.d.ts +7 -0
  145. package/dist/plugins/nyc/index.d.ts +10 -6
  146. package/dist/plugins/nyc/index.js +14 -12
  147. package/dist/plugins/nyc/types.d.ts +3 -0
  148. package/dist/plugins/nyc/types.js +1 -0
  149. package/dist/plugins/playwright/index.d.ts +15 -7
  150. package/dist/plugins/playwright/index.js +37 -19
  151. package/dist/plugins/playwright-ct/index.d.ts +11 -7
  152. package/dist/plugins/playwright-ct/index.js +14 -15
  153. package/dist/plugins/postcss/index.d.ts +10 -6
  154. package/dist/plugins/postcss/index.js +13 -15
  155. package/dist/plugins/prettier/index.d.ts +10 -6
  156. package/dist/plugins/prettier/index.js +19 -16
  157. package/dist/plugins/prettier/types.d.ts +8 -0
  158. package/dist/plugins/prettier/types.js +1 -0
  159. package/dist/plugins/release-it/index.d.ts +11 -7
  160. package/dist/plugins/release-it/index.js +16 -23
  161. package/dist/plugins/remark/index.d.ts +11 -7
  162. package/dist/plugins/remark/index.js +24 -23
  163. package/dist/plugins/remark/types.d.ts +3 -0
  164. package/dist/plugins/remark/types.js +1 -0
  165. package/dist/plugins/remix/index.d.ts +9 -7
  166. package/dist/plugins/remix/index.js +12 -15
  167. package/dist/plugins/rollup/index.d.ts +8 -6
  168. package/dist/plugins/rollup/index.js +10 -11
  169. package/dist/plugins/semantic-release/index.d.ts +11 -7
  170. package/dist/plugins/semantic-release/index.js +17 -21
  171. package/dist/plugins/semantic-release/types.d.ts +1 -1
  172. package/dist/plugins/sentry/index.d.ts +8 -6
  173. package/dist/plugins/sentry/index.js +10 -11
  174. package/dist/plugins/storybook/index.d.ts +13 -8
  175. package/dist/plugins/storybook/index.js +36 -20
  176. package/dist/plugins/storybook/types.d.ts +7 -0
  177. package/dist/plugins/stryker/index.d.ts +10 -6
  178. package/dist/plugins/stryker/index.js +18 -16
  179. package/dist/plugins/stylelint/index.d.ts +10 -6
  180. package/dist/plugins/stylelint/index.js +19 -23
  181. package/dist/plugins/stylelint/types.d.ts +4 -1
  182. package/dist/plugins/svelte/index.d.ts +10 -8
  183. package/dist/plugins/svelte/index.js +17 -12
  184. package/dist/plugins/tailwind/index.d.ts +8 -5
  185. package/dist/plugins/tailwind/index.js +11 -5
  186. package/dist/plugins/tsup/index.d.ts +10 -0
  187. package/dist/plugins/tsup/index.js +29 -0
  188. package/dist/plugins/tsup/types.d.ts +7 -0
  189. package/dist/plugins/tsup/types.js +1 -0
  190. package/dist/plugins/typedoc/index.d.ts +13 -7
  191. package/dist/plugins/typedoc/index.js +16 -16
  192. package/dist/plugins/typedoc/types.d.ts +1 -1
  193. package/dist/plugins/typescript/index.d.ts +11 -7
  194. package/dist/plugins/typescript/index.js +44 -27
  195. package/dist/plugins/unbuild/index.d.ts +10 -0
  196. package/dist/plugins/unbuild/index.js +20 -0
  197. package/dist/plugins/unbuild/types.d.ts +13 -0
  198. package/dist/plugins/unbuild/types.js +1 -0
  199. package/dist/plugins/vercel-og/index.d.ts +8 -0
  200. package/dist/plugins/vercel-og/index.js +14 -0
  201. package/dist/plugins/vite/index.d.ts +12 -6
  202. package/dist/plugins/vite/index.js +15 -11
  203. package/dist/plugins/vitest/helpers.d.ts +2 -2
  204. package/dist/plugins/vitest/index.d.ts +14 -9
  205. package/dist/plugins/vitest/index.js +83 -24
  206. package/dist/plugins/vitest/types.d.ts +22 -2
  207. package/dist/plugins/vue/index.d.ts +10 -0
  208. package/dist/plugins/vue/index.js +38 -0
  209. package/dist/plugins/vue/types.d.ts +5 -0
  210. package/dist/plugins/vue/types.js +1 -0
  211. package/dist/plugins/webpack/index.d.ts +18 -6
  212. package/dist/plugins/webpack/index.js +61 -38
  213. package/dist/plugins/webpack/types.d.ts +2 -1
  214. package/dist/plugins/wireit/index.d.ts +11 -0
  215. package/dist/plugins/wireit/index.js +19 -0
  216. package/dist/plugins/wireit/types.d.ts +3 -0
  217. package/dist/plugins/wireit/types.js +1 -0
  218. package/dist/plugins/yorkie/index.d.ts +11 -0
  219. package/dist/plugins/yorkie/index.js +22 -0
  220. package/dist/plugins.d.ts +3 -0
  221. package/dist/plugins.js +14 -0
  222. package/dist/reporters/codeowners.js +4 -4
  223. package/dist/reporters/index.d.ts +5 -4
  224. package/dist/reporters/index.js +2 -0
  225. package/dist/reporters/json.js +23 -16
  226. package/dist/reporters/markdown.d.ts +3 -0
  227. package/dist/reporters/markdown.js +40 -0
  228. package/dist/reporters/symbols.js +6 -5
  229. package/dist/reporters/util.d.ts +8 -2
  230. package/dist/reporters/util.js +11 -5
  231. package/dist/types/cli.d.ts +5 -1
  232. package/dist/types/config.d.ts +12 -10
  233. package/dist/types/exports.d.ts +36 -5
  234. package/dist/types/imports.d.ts +23 -5
  235. package/dist/types/imports.js +1 -1
  236. package/dist/types/issues.d.ts +14 -3
  237. package/dist/types/package-json.d.ts +41 -0
  238. package/dist/types/package-json.js +1 -0
  239. package/dist/types/plugins.d.ts +33 -12
  240. package/dist/types/util.d.ts +3 -0
  241. package/dist/types/util.js +1 -0
  242. package/dist/types/workspace.d.ts +16 -11
  243. package/dist/typescript/SourceFile.d.ts +5 -0
  244. package/dist/typescript/SourceFileManager.d.ts +1 -1
  245. package/dist/typescript/SourceFileManager.js +3 -3
  246. package/dist/typescript/ast-helpers.d.ts +10 -18
  247. package/dist/typescript/ast-helpers.js +28 -23
  248. package/dist/typescript/createHosts.d.ts +3 -2
  249. package/dist/typescript/createHosts.js +3 -2
  250. package/dist/typescript/getImportsAndExports.d.ts +12 -17
  251. package/dist/typescript/getImportsAndExports.js +228 -65
  252. package/dist/typescript/resolveModuleNames.d.ts +1 -1
  253. package/dist/typescript/resolveModuleNames.js +38 -12
  254. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +3 -0
  255. package/dist/typescript/visitors/dynamic-imports/importCall.js +90 -0
  256. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +3 -0
  257. package/dist/typescript/visitors/dynamic-imports/importType.js +9 -0
  258. package/dist/typescript/visitors/dynamic-imports/index.d.ts +3 -0
  259. package/dist/typescript/visitors/dynamic-imports/index.js +8 -0
  260. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +4 -0
  261. package/dist/typescript/visitors/dynamic-imports/jsDocType.js +26 -0
  262. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +3 -0
  263. package/dist/typescript/visitors/{imports → dynamic-imports}/propertyAccessCall.js +1 -1
  264. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +3 -0
  265. package/dist/typescript/visitors/{imports → dynamic-imports}/requireCall.js +5 -5
  266. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  267. package/dist/typescript/visitors/exports/exportAssignment.js +4 -2
  268. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  269. package/dist/typescript/visitors/exports/exportDeclaration.js +8 -2
  270. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  271. package/dist/typescript/visitors/exports/exportKeyword.js +72 -14
  272. package/dist/typescript/visitors/exports/index.d.ts +1 -1
  273. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  274. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +45 -22
  275. package/dist/typescript/visitors/helpers.d.ts +2 -0
  276. package/dist/typescript/visitors/helpers.js +8 -0
  277. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  278. package/dist/typescript/visitors/imports/importDeclaration.js +11 -7
  279. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  280. package/dist/typescript/visitors/imports/importEqualsDeclaration.js +1 -1
  281. package/dist/typescript/visitors/imports/index.d.ts +1 -1
  282. package/dist/typescript/visitors/imports/index.js +1 -13
  283. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  284. package/dist/typescript/visitors/imports/reExportDeclaration.js +23 -4
  285. package/dist/typescript/visitors/index.d.ts +6 -4
  286. package/dist/typescript/visitors/index.js +4 -0
  287. package/dist/typescript/visitors/scripts/bun.d.ts +3 -0
  288. package/dist/typescript/visitors/scripts/bun.js +9 -0
  289. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  290. package/dist/typescript/visitors/scripts/execa.js +2 -9
  291. package/dist/typescript/visitors/scripts/index.d.ts +1 -1
  292. package/dist/typescript/visitors/scripts/index.js +2 -1
  293. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  294. package/dist/util/Performance.d.ts +8 -5
  295. package/dist/util/Performance.js +30 -6
  296. package/dist/util/array.d.ts +3 -1
  297. package/dist/util/cli-arguments.d.ts +7 -2
  298. package/dist/util/cli-arguments.js +13 -6
  299. package/dist/util/debug.d.ts +5 -3
  300. package/dist/util/debug.js +35 -28
  301. package/dist/util/fs.d.ts +4 -0
  302. package/dist/util/fs.js +29 -3
  303. package/dist/util/get-included-issue-types.d.ts +1 -0
  304. package/dist/util/get-included-issue-types.js +21 -19
  305. package/dist/util/git.d.ts +1 -1
  306. package/dist/util/git.js +3 -3
  307. package/dist/util/glob.d.ts +3 -4
  308. package/dist/util/glob.js +9 -10
  309. package/dist/util/globby.d.ts +14 -0
  310. package/dist/util/globby.js +135 -0
  311. package/dist/util/loader.js +18 -6
  312. package/dist/util/modules.d.ts +9 -3
  313. package/dist/util/modules.js +22 -12
  314. package/dist/util/object.d.ts +1 -1
  315. package/dist/util/object.js +2 -0
  316. package/dist/util/path.d.ts +2 -0
  317. package/dist/util/path.js +6 -3
  318. package/dist/util/plugin.d.ts +7 -1
  319. package/dist/util/plugin.js +39 -3
  320. package/dist/util/regex.d.ts +4 -0
  321. package/dist/util/regex.js +4 -0
  322. package/dist/util/register.d.ts +2 -1
  323. package/dist/util/register.js +9 -13
  324. package/dist/util/require.d.ts +1 -0
  325. package/dist/util/require.js +20 -5
  326. package/dist/util/tag.d.ts +4 -0
  327. package/dist/util/tag.js +15 -0
  328. package/dist/util/type.d.ts +3 -0
  329. package/dist/util/type.js +16 -0
  330. package/dist/util/unwrap-function.d.ts +1 -0
  331. package/dist/util/unwrap-function.js +13 -0
  332. package/dist/version.d.ts +1 -1
  333. package/dist/version.js +1 -1
  334. package/license +1 -1
  335. package/package.json +105 -88
  336. package/schema-jsonc.json +11 -0
  337. package/schema.json +121 -31
  338. package/dist/plugins/eslint/fallback.d.ts +0 -1
  339. package/dist/plugins/eslint/fallback.js +0 -13
  340. package/dist/plugins/vite/types.d.ts +0 -4
  341. package/dist/typescript/visitors/imports/importCall.d.ts +0 -3
  342. package/dist/typescript/visitors/imports/importCall.js +0 -11
  343. package/dist/typescript/visitors/imports/jsDocType.d.ts +0 -3
  344. package/dist/typescript/visitors/imports/jsDocType.js +0 -11
  345. package/dist/typescript/visitors/imports/propertyAccessCall.d.ts +0 -3
  346. package/dist/typescript/visitors/imports/requireCall.d.ts +0 -3
  347. package/dist/util/compilers.js +0 -20
  348. package/dist/util/map.d.ts +0 -1
  349. package/dist/util/map.js +0 -6
  350. /package/dist/{plugins/vite → compilers}/types.js +0 -0
  351. /package/dist/{types/compilers.js → plugins/changesets/types.js} +0 -0
package/README.md CHANGED
@@ -3,927 +3,17 @@
3
3
  Knip finds **unused files, dependencies and exports** in your JavaScript and TypeScript projects. Less code and
4
4
  dependencies lead to improved performance, less maintenance and easier refactorings.
5
5
 
6
- ```ts
7
- export const myVar = true;
8
- ```
6
+ The documentation is available at [knip.dev][1].
9
7
 
10
- This is where ESLint stops: it handles files in isolation, so it does not know whether `myVar` is used somewhere else.
11
- This is where Knip starts: it lints the project as a whole and finds unused exports, files and dependencies.
12
-
13
- It's only human to forget to remove things that you no longer use. But how do you find out? Where do you start finding
14
- things that can be removed?
15
-
16
- The dots don't connect themselves. This is where Knip comes in:
17
-
18
- - [x] Finds **unused files, dependencies and exports**
19
- - [x] Finds used dependencies not listed in `package.json`
20
- - [x] Built-in support for [workspaces (monorepos)][1]
21
- - [x] Growing list of [built-in plugins][2]
22
- - [x] Use [compilers][3] to include other file types (e.g. `.mdx`, `.vue`, `.svelte`)
23
- - [x] Finds binaries and dependencies in npm scripts, and a lot more locations
24
- - [x] Finds unused members of classes and enums
25
- - [x] Finds duplicate exports
26
- - [x] Supports any combination of JavaScript and TypeScript
27
- - [x] Multiple built-in [reporters][4] (or use [custom reporters][5] and [preprocessors][6])
28
- - [x] Understands [JSDoc/TSDoc tags][7] (e.g. `@public` and `@internal`)
29
- - [x] Run Knip as part of your CI environment to detect issues and prevent regressions
30
-
31
- Knip shines in both small and large projects. It's a fresh take on keeping your projects clean & tidy!
32
-
33
- [![An orange cow with scissors, Van Gogh style][9]][8] <sup>_“An orange cow with scissors, Van Gogh style” - generated
34
- with OpenAI_</sup>
35
-
36
- For updates or questions, come hang out in [The Knip Barn (Discord)][10], or follow [@webprolific (Twitter)][11] or
37
- [@webpro (fosstodon.org)][12]. Please use GitHub to [report issues][13].
38
-
39
- ## Contents
40
-
41
- - [Getting Started][14]
42
- - [Installation][15]
43
- - [Default Configuration][16]
44
- - [Let's Go!][17]
45
- - [Configuration][18]
46
- - [Entry Files][19]
47
- - [Workspaces][1]
48
- - [Plugins][2]
49
- - [Compilers][3]
50
- - [Ignore files, binaries, dependencies and workspaces][20]
51
- - [Public exports][21]
52
- - [Ignore exports used in file][22]
53
- - [Include exports in entry files][23]
54
- - [Paths][24]
55
- - [Production Mode][25]
56
- - [Strict][26]
57
- - [Ignore `@internal` exports][27]
58
- - [Plugins][28]
59
- - [Output][29]
60
- - [Screenshots][30]
61
- - [Reading the report][31]
62
- - [Rules & Filters][32]
63
- - [Reporters][4]
64
- - [Fixing Issues][33]
65
- - [JSDoc tags][7]
66
- - [Command Line Options][34]
67
- - [Potential boost with `--no-gitignore`][35]
68
- - [Comparison & Migration][36]
69
- - [depcheck][37]
70
- - [unimported][38]
71
- - [ts-unused-exports][39]
72
- - [ts-prune][40]
73
- - [Projects using Knip][41]
74
- - [Articles, etc.][42]
75
- - [Why "Knip"?][43]
76
- - [Really, another unused file/dependency/export finder?][44]
77
- - [Contributors][45]
78
-
79
- ## Getting Started
80
-
81
- ### Installation
82
-
83
- npm install -D knip
84
-
85
- Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6.
86
-
87
- ### Default Configuration
88
-
89
- Knip has good defaults and you can run it without any configuration. The (simplified) default config:
90
-
91
- ```json
92
- {
93
- "entry": ["index.js", "src/index.js"],
94
- "project": ["**/*.js"]
95
- }
96
- ```
97
-
98
- There's more, jump to [Entry Files][19] for details.
99
-
100
- Places where Knip looks for configuration (ordered by priority):
101
-
102
- - `knip.json`
103
- - `knip.jsonc`
104
- - `.knip.json`
105
- - `.knip.jsonc`
106
- - `knip.ts`
107
- - `knip.js`
108
- - `package.json#knip`
109
-
110
- You can use a dynamic `knip.ts` with TypeScript if you prefer:
111
-
112
- ```ts
113
- import type { KnipConfig } from 'knip';
114
-
115
- const config: KnipConfig = {
116
- entry: ['src/index.ts'],
117
- project: ['src/**/*.ts'],
118
- };
119
-
120
- export default config;
121
- ```
122
-
123
- Use `--config path/to/knip.json` to use a different location.
124
-
125
- ### Let's Go!
126
-
127
- Run the checks with `npx knip`. Or first add this script to `package.json`:
128
-
129
- ```json
130
- {
131
- "scripts": {
132
- "knip": "knip"
133
- }
134
- }
135
- ```
136
-
137
- Then use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine
138
- with `yarn` or `pnpm` as well.
139
-
140
- See [Command Line Options][34] for an overview of available CLI options.
141
-
142
- ## Configuration
143
-
144
- ### Entry Files
145
-
146
- In addition to `index.js`, the following file names and extensions are also considered entry files:
147
-
148
- - `index`, `main` and `cli`
149
- - `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`
150
-
151
- This means files like `main.cjs` and `src/cli.ts` are automatically added as entry files. Knip looks for entry files at
152
- those default locations, but also in other places:
153
-
154
- - The `main`, `bin` and `exports` fields of `package.json`.
155
- - [Plugins][2] such as for Next.js, Remix, Gatsby or Svelte add entry files.
156
- - The `scripts` in package.json or other scripts may provide entry files.
157
-
158
- Knip does this for each [workspace][1] it finds, trying to minimize the configuration to suit your project. In a
159
- perfectly boring world where everything is according to defaults you wouldn't even need a `knip.json` file at all.
160
-
161
- Larger projects tend to have more things customized, and therefore probably get more out of Knip with a configuration
162
- file. Let's say you are using `.ts` files exclusively and have all source files only in the `src` directory:
163
-
164
- ```json
165
- {
166
- "$schema": "https://unpkg.com/knip@2/schema.json",
167
- "entry": ["src/index.ts"],
168
- "project": ["src/**/*.ts"]
169
- }
170
- ```
171
-
172
- The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
173
- contain all files to match against the files resolved from the entry files, including potentially unused files.
174
-
175
- ### Workspaces
176
-
177
- Workspaces are handled out-of-the-box by Knip. Every workspace is part of the analysis.
178
-
179
- Workspaces are sometimes also referred to as package-based monorepos, or as packages in a monorepo. Knip uses the term
180
- workspace exclusively to indicate a directory that has a `package.json`.
181
-
182
- Here's an example `knip.json` configuration with some custom `entry` and `project` patterns:
183
-
184
- ```json
185
- {
186
- "workspaces": {
187
- ".": {
188
- "entry": "scripts/*.js",
189
- "project": "scripts/**/*.js"
190
- },
191
- "packages/*": {
192
- "entry": "{index,cli}.ts",
193
- "project": "**/*.ts"
194
- },
195
- "packages/my-lib": {
196
- "entry": "main.js"
197
- }
198
- }
199
- }
200
- ```
201
-
202
- It might be useful to run Knip first with no or little configuration to see where it needs custom `entry` and/or
203
- `project` files. Each workspace has the same [default configuration][18].
204
-
205
- The root workspace is named `"."` under `workspaces` (like in the example).
206
-
207
- Knip supports workspaces as defined in three possible locations:
208
-
209
- - In the `workspaces` array in `package.json` (npm, Yarn, Lerna).
210
- - In the `packages` array in `pnpm-workspace.yaml` (pnpm).
211
- - In the `workspaces.packages` array in `package.json` (legacy).
212
- - In the `workspaces` object in Knip configuration.
213
-
214
- The `workspaces` in Knip configuration not already defined in the root `package.json` or `pnpm-workspace.yaml` are
215
- added. Knip requires a `package.json` file in each workspace directory.
216
-
217
- Here's some example output when running Knip in a workspace:
218
-
219
- <img src="./assets/screenshot-workspaces.png" alt="example output in workspaces" width="578">
220
-
221
- Use `--debug` to get more verbose output.
222
-
223
- Use `--workspace [dir]` to analyze a single workspace (including its ancestors).
224
-
225
- The `ignore`, `ignoreBinaries` and `ignoreDependencies` options are available inside workspace configurations.
226
-
227
- ### Plugins
228
-
229
- Plugins tell Knip where to look for configuration and entry files, and if necessary have a custom dependency finder.
230
- Knip plugins are automatically activated, you don't need to install or configure anything.
231
-
232
- To explain what they do, here's a quick example `.eslintrc.json` configuration file (for ESLint):
233
-
234
- ```json
235
- {
236
- "extends": ["airbnb"],
237
- "plugins": ["prettier"]
238
- }
239
- ```
240
-
241
- Knip's ESLint plugin reads `.eslintrc.json` and will return `eslint-config-airbnb` and `eslint-plugin-prettier` from
242
- this example to Knip, so it can tell you whether `package.json` is out of sync. In a nutshell, this is how plugins work.
243
- This is especially useful over time when such configuration files change (and they will)!
244
-
245
- Knip contains a growing list of plugins:
246
-
247
- - [Angular][plugin-angular]
248
- - [Ava][plugin-ava]
249
- - [Babel][plugin-babel]
250
- - [Capacitor][plugin-capacitor]
251
- - [Changesets][plugin-changesets]
252
- - [Commitizen][plugin-commitizen]
253
- - [commitlint][plugin-commitlint]
254
- - [cspell][plugin-cspell]
255
- - [Cypress][plugin-cypress]
256
- - [Drizzle][plugin-drizzle]
257
- - [ESLint][plugin-eslint]
258
- - [Gatsby][plugin-gatsby]
259
- - [GitHub Actions][plugin-github-actions]
260
- - [husky][plugin-husky]
261
- - [Jest][plugin-jest]
262
- - [Lefthook][plugin-lefthook]
263
- - [lint-staged][plugin-lint-staged]
264
- - [markdownlint][plugin-markdownlint]
265
- - [Mocha][plugin-mocha]
266
- - [Next.js][plugin-next]
267
- - [Node.js Test Runner][plugin-node-test-runner]
268
- - [npm-package-json-lint][plugin-npm-package-json-lint]
269
- - [Nx][plugin-nx]
270
- - [nyc][plugin-nyc]
271
- - [Playwright][plugin-playwright]
272
- - [Playwright for components][plugin-playwright-ct]
273
- - [PostCSS][plugin-postcss]
274
- - [Prettier][plugin-prettier]
275
- - [Release It][plugin-release-it]
276
- - [Remark][plugin-remark]
277
- - [Remix][plugin-remix]
278
- - [Rollup][plugin-rollup]
279
- - [Semantic Release][plugin-semantic-release]
280
- - [Sentry][plugin-sentry]
281
- - [Storybook][plugin-storybook]
282
- - [Stryker][plugin-stryker]
283
- - [Stylelint][plugin-stylelint]
284
- - [Svelte][plugin-svelte]
285
- - [Tailwind][plugin-tailwind]
286
- - [TypeDoc][plugin-typedoc]
287
- - [TypeScript][plugin-typescript]
288
- - [Vite][plugin-vite]
289
- - [Vitest][plugin-vitest]
290
- - [Webpack][plugin-webpack]
291
-
292
- Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
293
- whether one of a few dependencies is listed in `package.json`. Once enabled, they add a set of `config` files for
294
- themselves and/or `entry` files for Knip to analyze.
295
-
296
- - `config` files are given to the plugin's dependency finder
297
- - `entry` files are given to Knip to include with the analysis of the rest of the source code
298
-
299
- See each plugin's documentation for its default values.
300
-
301
- #### `config`
302
-
303
- Plugins usually include `config` files. They are handled by the plugin's custom dependency finder, which returns all
304
- dependencies referenced in the files it is given. Knip handles the rest to determine which of those dependencies are
305
- unused or missing.
306
-
307
- #### `entry`
308
-
309
- Other configuration files use `require` or `import` statements to use dependencies, so they don't need special handing
310
- and can be analyzed like any other source file. That's why these configuration files are also used as `entry` files.
311
-
312
- #### Override plugin configuration
313
-
314
- Usually, no custom configuration is required for plugins, but if your project uses custom file locations then Knip
315
- allows you to override any defaults. Let's take Cypress for example. By default it uses `cypress.config.js`, but your
316
- project uses `config/cypress.js`. Also, the default pattern for test files is `cypress/e2e/**/*.cy.js`, but your project
317
- has them at `e2e-tests/*.spec.ts`. Here's how to configure this:
318
-
319
- ```json
320
- {
321
- "cypress": {
322
- "entry": ["config/cypress.js", "e2e-tests/*.spec.js"]
323
- }
324
- }
325
- ```
326
-
327
- When overriding any plugin's configuration, the options object is fully replaced. Look at the plugin's page to find the
328
- default configuration and use that as a basis. Here's another example to override the test file pattern for Vitest:
329
-
330
- ```json
331
- {
332
- "vitest": {
333
- "config": ["vitest.config.ts"],
334
- "entry": ["**/*.vitest.ts"]
335
- }
336
- }
337
- ```
338
-
339
- This plugin configuration can be set on root and workspace level. If set on root level, it can be disabled on workspace
340
- level by setting it to `false` there.
341
-
342
- #### Multi-project repositories
343
-
344
- Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
345
- repository (such as the [Nx "intregrated repo" style][46]). Let's assume some of these projects are apps and have their
346
- own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
347
-
348
- ```json
349
- {
350
- "cypress": {
351
- "entry": ["apps/**/cypress.config.ts", "apps/**/cypress/e2e/*.spec.ts"]
352
- }
353
- }
354
- ```
355
-
356
- #### Disable a plugin
357
-
358
- In case a plugin causes issues, it can be disabled by using `false` as its value (e.g. `"webpack": false`).
359
-
360
- #### Create a new plugin
361
-
362
- Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][47]. This
363
- guide also contains more details if you want to learn more about plugins and why they are useful.
364
-
365
- ### Compilers
366
-
367
- Compilers allow to include files that are not JavaScript or TypeScript in the process of finding unused or missing
368
- dependencies (e.g. `.mdx`, `.vue` and `.svelte` files).
369
-
370
- This requires using a dynamic `knip.js` or `knip.ts` configuration file. Provide a `compilers` object in the
371
- configuration where each key represents the extension and the value is a function that takes the contents of these files
372
- as input and returns JavaScript or TypeScript as output. Here is an example that compiles `.mdx` files to JavaScript so
373
- these files and their imports and exports become part of the analysis:
374
-
375
- ```js
376
- import { compileSync } from 'mdx-js/mdx';
377
-
378
- export default {
379
- compilers: {
380
- mdx: compileSync,
381
- },
382
- };
383
- ```
384
-
385
- Read [Compilers][48] for more details and examples.
386
-
387
- ### Ignore files, binaries, dependencies and workspaces
388
-
389
- There are a few ways to tell Knip to ignore certain files, binaries, dependencies and workspaces. Some examples:
390
-
391
- ```json
392
- {
393
- "ignore": ["**/*.d.ts", "**/fixtures"],
394
- "ignoreBinaries": ["zip", "docker-compose"],
395
- "ignoreDependencies": ["hidden-package"],
396
- "ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
397
- }
398
- ```
399
-
400
- These can also be configured per workspace (except for `ignoreWorkspaces`).
401
-
402
- ### Public exports
403
-
404
- Sometimes a file that's not an entry file has one or more exports that are public and should not be reported as unused.
405
- Such variables and types can be marked with the JSDoc `@public` tag:
406
-
407
- ```js
408
- /**
409
- * Merge two objects.
410
- *
411
- * @public
412
- */
413
-
414
- export const merge = function () {};
415
-
416
- /** @public */
417
- export const split = function () {};
418
- ```
419
-
420
- Knip does not report public exports and types as unused.
421
-
422
- ### Ignore exports used in file
423
-
424
- In files with multiple exports, some of them might be used only internally. If these exports should not be reported,
425
- there is a `ignoreExportsUsedInFile` option available. With this option enabled, you don't need to mark everything
426
- `@public` separately and when something is no longer used internally, it will still be reported.
427
-
428
- ```json
429
- {
430
- "ignoreExportsUsedInFile": true
431
- }
432
- ```
433
-
434
- In a more fine-grained manner, you can also ignore only specific issue types:
435
-
436
- ```json
437
- {
438
- "ignoreExportsUsedInFile": {
439
- "interface": true,
440
- "type": true
441
- }
442
- }
443
- ```
444
-
445
- ### Include exports in entry files
446
-
447
- When a repository is self-contained or private, you may want to include entry files when reporting unused exports:
448
-
449
- knip --include-entry-exports
450
-
451
- Knip will also report unused exports in entry source files and scripts (such as those referenced in `package.json`). But
452
- not in entry and configuration files from plugins, such as `next.config.js` or `src/routes/+page.svelte`.
453
-
454
- ### Paths
455
-
456
- Tools like TypeScript, Webpack and Babel support import aliases in various ways. Knip automatically includes
457
- `compilerOptions.paths` from the TypeScript configuration, but does not (yet) automatically find other types of import
458
- aliases. They can be configured manually:
459
-
460
- ```json
461
- {
462
- "$schema": "https://unpkg.com/knip@2/schema.json",
463
- "paths": {
464
- "@lib": ["./lib/index.ts"],
465
- "@lib/*": ["./lib/*"]
466
- }
467
- }
468
- ```
469
-
470
- Each workspace can also have its own `paths` configured. Knip `paths` follow the TypeScript semantics:
471
-
472
- - Path values are an array of relative paths.
473
- - Paths without an `*` are exact matches.
474
-
475
- ## Production Mode
476
-
477
- The default mode for Knip is holistic and targets all project code, including configuration files and tests. Test files
478
- usually import production files. This prevents the production files or their exports from being reported as unused,
479
- while sometimes both of them can be removed. This is why Knip has a "production mode".
480
-
481
- To tell Knip what is production code, add an exclamation mark behind each `pattern!` that is meant for production and
482
- use the `--production` flag. Here's an example:
483
-
484
- ```json
485
- {
486
- "entry": ["src/index.ts!", "build/script.js"],
487
- "project": ["src/**/*.ts!", "build/*.js"]
488
- }
489
- ```
490
-
491
- Here's what's included in production mode analysis:
492
-
493
- - Only `entry` and `project` patterns suffixed with `!`.
494
- - Only production `entry` file patterns exported by plugins (such as Next.js and Gatsby).
495
- - Only the `start` and `postinstall` scripts (e.g. not the `test` or other npm scripts in `package.json`).
496
- - Only unused `exports`, `nsExports` and `classMembers` are reported (not `types`, `nsTypes`, `enumMembers`).
497
-
498
- ### Strict
499
-
500
- Additionally, the `--strict` flag can be used to:
501
-
502
- - Consider `dependencies` (not `devDependencies`) when finding unused or unlisted dependencies.
503
- - Include `peerDependencies` when finding unused or unlisted dependencies.
504
- - Ignore type-only imports (`import type {}`).
505
- - Verify each workspace is self-contained: have their own `dependencies` (and not use packages of ancestor workspaces).
506
-
507
- ### Ignore `@internal` exports
508
-
509
- In addition to the flags above, the `--ignore-internal` flag can be used to ignore exports tagged with `@internal`. This
510
- can be useful in production mode, since `@internal` exports might be only imported from non-production code.
511
-
512
- ### Plugins
513
-
514
- Plugins also have this distinction. For instance, Next.js entry files for pages (`pages/**/*.tsx`) and Remix routes
515
- (`app/routes/**/*.tsx`) represent production code, while Jest and Storybook entry files (e.g. `*.spec.ts` or
516
- `*.stories.js`) do not. All of this is handled automatically by Knip and its plugins.
517
-
518
- ## Output
519
-
520
- ### Screenshots
521
-
522
- Here's an example run using the default reporter:
523
-
524
- <img src="./assets/screenshot-exports.png" alt="example output of exported values and types" width="578">
525
-
526
- This example shows more output related to unused and unlisted dependencies:
527
-
528
- <img src="./assets/screenshot-dependencies.png" alt="example output of dependencies" width="578">
529
-
530
- ### Reading the report
531
-
532
- The report contains the following types of issues:
533
-
534
- | Title | Description | Key |
535
- | :---------------------------------- | :---------------------------------------------- | :------------- |
536
- | Unused files | unable to find references to this file | `files` |
537
- | Unused dependencies | unable to find references to this dependency | `dependencies` |
538
- | Unused devDependencies | unable to find references to this devDependency | `dependencies` |
539
- | Unlisted dependencies | used dependencies not listed in package.json | `unlisted` |
540
- | Unlisted binaries | binaries from deps not listed in package.json | `binaries` |
541
- | Unresolved imports | unable to resolve this (import) specifier | `unresolved` |
542
- | Unused exports | unable to find references to this export | `exports` |
543
- | Unused exports in namespaces | unable to find direct references to this export | `nsExports` |
544
- | Unused exported types | unable to find references to this exported type | `types` |
545
- | Unused exported types in namespaces | unable to find direct references to this export | `nsTypes` |
546
- | Unused exported enum members | unable to find references to this enum member | `enumMembers` |
547
- | Unused exported class members | unable to find references to this class member | `classMembers` |
548
- | Duplicate exports | the same thing is exported more than once | `duplicates` |
549
-
550
- When an issue type has zero issues, it is not shown.
551
-
552
- Getting too many reported issues and false positives? Read more about [handling issues][49].
553
-
554
- ### Rules & Filters
555
-
556
- Use rules or filters if you don't (yet) want all issue types Knip reports.
557
-
558
- #### Rules
559
-
560
- Use `rules` in the configuration to customize the issue types that count towards the total error count, or to exclude
561
- them altogether.
562
-
563
- - `error` (default): printed, adds to total error count (similar to the `--include` filter)
564
- - `warn`: printed in faded/grey color, does not add to error count (i.e. the exit code)
565
- - `off`: not printed, does not add to error count (similar to the `--exclude` filter)
566
-
567
- Example:
568
-
569
- ```json
570
- {
571
- "rules": {
572
- "files": "warn",
573
- "classMembers": "off",
574
- "duplicates": "off"
575
- }
576
- }
577
- ```
578
-
579
- See [reading the report][31] for the list of issue types.
580
-
581
- The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
582
- apply filters or configurations only to a specific issue type.
583
-
584
- #### Filters
585
-
586
- You can `--include` or `--exclude` any of the reported issue types to slice & dice the report to your needs.
587
- Alternatively, they can be added to the configuration (e.g. `"exclude": ["dependencies"]`).
588
-
589
- Use `--include` to report only specific issue types (the following example commands do the same):
590
-
591
- knip --include files --include dependencies
592
- knip --include files,dependencies
593
-
594
- Use `--exclude` to ignore reports you're not interested in:
595
-
596
- knip --include files --exclude classMembers,enumMembers
597
-
598
- Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
599
-
600
- See [reading the report][31] for the list of issue types.
601
-
602
- #### When to use rules or filters
603
-
604
- Filters are meant to be used as command-line flags, rules allow for more fine-grained configuration.
605
-
606
- - Rules are more fine-grained since they also have "warn".
607
- - Rules could be extended in the future.
608
- - Filters can be set in configuration and from CLI, rules only in configuration.
609
- - Filters have two groups (`--dependencies` and `--exports`), rules don't have any grouping.
610
-
611
- ### Reporters
612
-
613
- Knip provides the following built-in reporters:
614
-
615
- - codeowners
616
- - compact
617
- - json
618
- - symbol (default)
619
-
620
- #### Custom Reporters
621
-
622
- When the provided built-in reporters are not sufficient, a custom reporter can be implemented.
623
-
624
- Find more details in [reporters and preprocessors][50].
625
-
626
- #### Preprocessers
627
-
628
- Use preprocessers to modify the results before they're passed to the reporter(s).
629
-
630
- Find more details in [reporters and preprocessors][50].
631
-
632
- ## Fixing Issues
633
-
634
- This is the fun part! Knip, knip, knip ✂️
635
-
636
- Tip: back up files or use an VCS like Git before deleting files or making changes. Run tests to verify results.
637
-
638
- - Unused files can be removed.
639
- - Unused dependencies can be removed from `package.json`.
640
- - Unlisted dependencies should be added to `package.json`.
641
- - Unresolved imports should be reviewed.
642
- - Unused exports and types: remove the `export` keyword in front of unused exports. Then you can see whether the
643
- variable or type is used within the same file. If this is not the case, it can be removed.
644
- - Duplicate exports can be removed so they're exported only once.
645
-
646
- Repeat the process to reveal new unused files and exports. It's so liberating to remove unused things!
647
-
648
- Getting too many reported issues and false positives? Read more about [handling issues][49] describing potential causes
649
- for false positives, and how to handle them.
650
-
651
- ## JSDoc tags
652
-
653
- Knip takes the following JSDoc/TSDoc tags into account:
654
-
655
- | Tag | Description |
656
- | :---------- | :------------------------------------------------------ |
657
- | `@public` | Do not report this unused export, type or member |
658
- | `@beta` | ^^ Idem |
659
- | `@internal` | Do not report this unused export in `--production` mode |
660
- | `@alias` | Do not report this duplicate export |
661
-
662
- ## Command Line Options
663
-
664
- $ npx knip --help
665
- ✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
666
-
667
- Usage: knip [options]
668
-
669
- Options:
670
- -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
671
- -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)
672
- --production Analyze only production source files (e.g. no tests, devDependencies, exported types)
673
- --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
674
- --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
675
- -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
676
- --no-gitignore Don't use .gitignore
677
- --include Report only provided issue type(s), can be comma-separated or repeated (1)
678
- --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
679
- --dependencies Shortcut for --include dependencies,unlisted,unresolved
680
- --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
681
- --include-entry-exports Include entry files when reporting unused exports
682
- -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
683
- --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
684
- --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
685
- --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
686
- --reporter-options Pass extra options to the reporter (as JSON string, see example)
687
- --no-config-hints Suppress configuration hints
688
- --no-exit-code Always exit with code zero (0)
689
- --max-issues Maximum number of issues before non-zero exit code (default: 0)
690
- -d, --debug Show debug output
691
- --debug-file-filter Filter for files in debug output (regex as string)
692
- --performance Measure count and running time of expensive functions and display stats table
693
- -h, --help Print this help text
694
- -V, --version Print version
695
-
696
- (1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
697
-
698
- Examples:
699
-
700
- $ knip
701
- $ knip --production
702
- $ knip --workspace packages/client --include files,dependencies
703
- $ knip -c ./config/knip.json --reporter compact
704
- $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
705
- $ knip --debug --debug-file-filter '(specific|particular)-module'
706
-
707
- More documentation and bug reports: https://github.com/webpro/knip
708
-
709
- ## Potential boost with `--no-gitignore`
710
-
711
- To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][51].
712
-
713
- ## Comparison & Migration
714
-
715
- This table is an ongoing comparison. Based on their docs (please report any mistakes):
716
-
717
- | Feature | **knip** | [depcheck][52] | [unimported][53] | [ts-unused-exports][54] | [ts-prune][55] |
718
- | :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
719
- | Unused files | ✅ | - | ✅ | - | - |
720
- | Unused dependencies | ✅ | ✅ | ✅ | - | - |
721
- | Unlisted dependencies | ✅ | ✅ | ✅ | - | - |
722
- | [Plugins][2] | ✅ | ✅ | ❌ | - | - |
723
- | [Compilers][3] | ✅ | - | - | - | - |
724
- | Unused exports | ✅ | - | - | ✅ | ✅ |
725
- | Unused class members | ✅ | - | - | - | - |
726
- | Unused enum members | ✅ | - | - | - | - |
727
- | Duplicate exports | ✅ | - | - | ❌ | ❌ |
728
- | Search namespaces | ✅ | - | - | ✅ | ❌ |
729
- | Custom reporters | ✅ | - | - | - | - |
730
- | JavaScript support | ✅ | ✅ | ✅ | - | - |
731
- | Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
732
- | [Workspaces][1] | ✅ | ❌ | ❌ | - | - |
733
- | ESLint plugin available | - | - | - | ✅ | - |
734
-
735
- ✅ = Supported, ❌ = Not supported, - = Out of scope
736
-
737
- Below some similar commands to get another idea of what Knip does in comparison:
738
-
739
- ### depcheck
740
-
741
- The following commands are similar:
742
-
743
- depcheck
744
- knip --dependencies
745
-
746
- ### unimported
747
-
748
- The following commands are similar:
749
-
750
- unimported
751
- knip --production --dependencies --include files
752
-
753
- Also see [production mode][25].
754
-
755
- ### ts-unused-exports
756
-
757
- The following commands are similar:
758
-
759
- ts-unused-exports
760
- knip --include exports,types,nsExports,nsTypes
761
- knip --exports # Adds unused enum and class members
762
-
763
- ### ts-prune
764
-
765
- The following commands are similar:
766
-
767
- ts-prune
768
- knip --include exports,types
769
- knip --exports # Adds unused exports/types in namespaces and unused enum/class members
770
-
771
- ## Projects using Knip
772
-
773
- Many thanks to some of the early adopters of Knip:
774
-
775
- - [Block Protocol][56]
776
- - [DeepmergeTS][57]
777
- - [eslint-plugin-functional][58]
778
- - [freeCodeCamp.org][59]
779
- - [is-immutable-type][60]
780
- - [IsaacScript][61]
781
- - [Nuxt][62]
782
- - [Owncast][63]
783
- - [release-it][64]
784
- - [Template TypeScript Node Package][65]
785
- - [Tipi][66]
786
-
787
- ## Articles, etc.
788
-
789
- - Discord: hang out in [The Knip Barn][10]
790
- - Ask your questions in the [Knip knowledge base][67] (powered by OpenAI and [7-docs][68], experimental!)
791
- - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][69]
792
- - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][70]
793
- - Josh Goldberg: [Speeding Up Centered Part 4: Unused Code Bloat][71]
794
-
795
- ## Why "Knip"?
796
-
797
- Knip is Dutch for a "cut". A Dutch expression is "ergens ge**knip**t voor zijn", which means to be perfectly suited for
798
- the job. I'm motivated to make Knip perfectly suited for the job of cutting projects to perfection! ✂️
799
-
800
- ## Really, another unused file/dependency/export finder?
801
-
802
- As listed above, there are already some great packages available if you want to find unused dependencies OR unused
803
- exports. I love the Unix philosophy ("do one thing well"). But looking at what Knip does, I believe it's efficient to
804
- handle multiple concerns in a single tool. When building a dependency graph of the project, an abstract syntax tree for
805
- each file, and traversing all of this, why not collect the various issues in one go?
8
+ This package is part of [the Knip monorepo][2].
806
9
 
807
10
  ## Contributors
808
11
 
809
12
  Special thanks to the wonderful people who have contributed to this project:
810
13
 
811
- [![Contributors][73]][72]
14
+ [![Contributors][4]][3]
812
15
 
813
- [1]: #workspaces
814
- [2]: #plugins
815
- [3]: #compilers
816
- [4]: #reporters
817
- [5]: #custom-reporters
818
- [6]: #preprocessers
819
- [7]: #jsdoc-tags
820
- [8]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
821
- [9]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
822
- [10]: https://discord.gg/r5uXTtbTpc
823
- [11]: https://twitter.com/webprolific
824
- [12]: https://fosstodon.org/@webpro
825
- [13]: https://github.com/webpro/knip/issues
826
- [14]: #getting-started
827
- [15]: #installation
828
- [16]: #default-configuration
829
- [17]: #lets-go
830
- [18]: #configuration
831
- [19]: #entry-files
832
- [20]: #ignore-files-binaries-dependencies-and-workspaces
833
- [21]: #public-exports
834
- [22]: #ignore-exports-used-in-file
835
- [23]: #include-exports-in-entry-files
836
- [24]: #paths
837
- [25]: #production-mode
838
- [26]: #strict
839
- [27]: #ignore-internal-exports
840
- [28]: #plugins-1
841
- [29]: #output
842
- [30]: #screenshots
843
- [31]: #reading-the-report
844
- [32]: #rules--filters
845
- [33]: #fixing-issues
846
- [34]: #command-line-options
847
- [35]: #potential-boost-with---no-gitignore
848
- [36]: #comparison--migration
849
- [37]: #depcheck
850
- [38]: #unimported
851
- [39]: #ts-unused-exports
852
- [40]: #ts-prune
853
- [41]: #projects-using-knip
854
- [42]: #articles-etc
855
- [43]: #why-knip
856
- [44]: #really-another-unused-filedependencyexport-finder
857
- [45]: #contributors
858
- [46]: https://nx.dev/concepts/integrated-vs-package-based
859
- [47]: ./docs/writing-a-plugin.md
860
- [48]: ./docs/compilers.md
861
- [49]: ./docs/handling-issues.md
862
- [50]: ./docs/reporters-and-preprocessors.md
863
- [51]: ./docs/perf-boost-with-no-gitignore.md
864
- [52]: https://github.com/depcheck/depcheck
865
- [53]: https://github.com/smeijer/unimported
866
- [54]: https://github.com/pzavolinsky/ts-unused-exports
867
- [55]: https://github.com/nadeesha/ts-prune
868
- [56]: https://github.com/blockprotocol/blockprotocol
869
- [57]: https://github.com/RebeccaStevens/deepmerge-ts
870
- [58]: https://github.com/eslint-functional/eslint-plugin-functional
871
- [59]: https://github.com/freeCodeCamp/freeCodeCamp
872
- [60]: https://github.com/RebeccaStevens/is-immutable-type
873
- [61]: https://github.com/IsaacScript/isaacscript
874
- [62]: https://github.com/nuxt/nuxt
875
- [63]: https://github.com/owncast/owncast
876
- [64]: https://github.com/release-it/release-it
877
- [65]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
878
- [66]: https://github.com/meienberger/runtipi
879
- [67]: https://knip.deno.dev
880
- [68]: https://github.com/7-docs/7-docs
881
- [69]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
882
- [70]: https://effectivetypescript.com/2023/07/29/knip/
883
- [71]: https://www.joshuakgoldberg.com/blog/speeding-up-centered-part-4-unused-code-bloat/
884
- [72]: https://github.com/webpro/knip/graphs/contributors
885
- [73]: https://contrib.rocks/image?repo=webpro/knip
886
- [plugin-angular]: ./src/plugins/angular
887
- [plugin-ava]: ./src/plugins/ava
888
- [plugin-babel]: ./src/plugins/babel
889
- [plugin-capacitor]: ./src/plugins/capacitor
890
- [plugin-changesets]: ./src/plugins/changesets
891
- [plugin-commitizen]: ./src/plugins/commitizen
892
- [plugin-commitlint]: ./src/plugins/commitlint
893
- [plugin-cspell]: ./src/plugins/cspell
894
- [plugin-cypress]: ./src/plugins/cypress
895
- [plugin-drizzle]: ./src/plugins/drizzle
896
- [plugin-eslint]: ./src/plugins/eslint
897
- [plugin-gatsby]: ./src/plugins/gatsby
898
- [plugin-github-actions]: ./src/plugins/github-actions
899
- [plugin-husky]: ./src/plugins/husky
900
- [plugin-jest]: ./src/plugins/jest
901
- [plugin-lefthook]: ./src/plugins/lefthook
902
- [plugin-lint-staged]: ./src/plugins/lint-staged
903
- [plugin-markdownlint]: ./src/plugins/markdownlint
904
- [plugin-mocha]: ./src/plugins/mocha
905
- [plugin-next]: ./src/plugins/next
906
- [plugin-node-test-runner]: ./src/plugins/node-test-runner
907
- [plugin-npm-package-json-lint]: ./src/plugins/npm-package-json-lint
908
- [plugin-nx]: ./src/plugins/nx
909
- [plugin-nyc]: ./src/plugins/nyc
910
- [plugin-playwright]: ./src/plugins/playwright
911
- [plugin-playwright-ct]: ./src/plugins/playwright-ct
912
- [plugin-postcss]: ./src/plugins/postcss
913
- [plugin-prettier]: ./src/plugins/prettier
914
- [plugin-release-it]: ./src/plugins/release-it
915
- [plugin-remark]: ./src/plugins/remark
916
- [plugin-remix]: ./src/plugins/remix
917
- [plugin-rollup]: ./src/plugins/rollup
918
- [plugin-semantic-release]: ./src/plugins/semantic-release
919
- [plugin-sentry]: ./src/plugins/sentry
920
- [plugin-storybook]: ./src/plugins/storybook
921
- [plugin-stryker]: ./src/plugins/stryker
922
- [plugin-stylelint]: ./src/plugins/stylelint
923
- [plugin-svelte]: ./src/plugins/svelte
924
- [plugin-tailwind]: ./src/plugins/tailwind
925
- [plugin-typedoc]: ./src/plugins/typedoc
926
- [plugin-typescript]: ./src/plugins/typescript
927
- [plugin-vite]: ./src/plugins/vite
928
- [plugin-vitest]: ./src/plugins/vitest
929
- [plugin-webpack]: ./src/plugins/webpack
16
+ [1]: https://knip.dev
17
+ [2]: https://github.com/webpro/knip
18
+ [3]: https://github.com/webpro/knip/graphs/contributors
19
+ [4]: https://contrib.rocks/image?repo=webpro/knip