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