@knip/mcp 0.0.21 → 0.0.23
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.
- package/package.json +3 -3
- package/src/docs/docs/blog/brief-history.md +2 -3
- package/src/docs/docs/blog/for-editors-and-agents.md +2 -3
- package/src/docs/docs/blog/knip-v3.mdx +1 -1
- package/src/docs/docs/blog/knip-v4.mdx +1 -1
- package/src/docs/docs/blog/knip-v5.mdx +1 -1
- package/src/docs/docs/blog/knip-v6.md +145 -0
- package/src/docs/docs/blog/release-notes-v2.md +1 -1
- package/src/docs/docs/blog/slim-down-to-speed-up.md +1 -1
- package/src/docs/docs/blog/state-of-knip.md +1 -1
- package/src/docs/docs/blog/two-years.mdx +1 -1
- package/src/docs/docs/explanations/comparison-and-migration.md +2 -2
- package/src/docs/docs/features/auto-fix.mdx +3 -33
- package/src/docs/docs/features/reporters.md +16 -13
- package/src/docs/docs/features/rules-and-filters.md +1 -1
- package/src/docs/docs/guides/handling-issues.mdx +32 -48
- package/src/docs/docs/guides/issue-reproduction.md +4 -8
- package/src/docs/docs/guides/performance.md +7 -62
- package/src/docs/docs/guides/using-knip-in-ci.md +2 -2
- package/src/docs/docs/index.mdx +3 -3
- package/src/docs/docs/overview/configuration.md +1 -1
- package/src/docs/docs/overview/getting-started.mdx +1 -1
- package/src/docs/docs/reference/cli.md +31 -56
- package/src/docs/docs/reference/configuration.md +7 -7
- package/src/docs/docs/reference/faq.md +48 -63
- package/src/docs/docs/reference/integrations.md +1 -2
- package/src/docs/docs/reference/issue-types.md +17 -17
- package/src/docs/docs/reference/jsdoc-tsdoc-tags.md +1 -1
- package/src/docs/docs/reference/plugins/angular.md +34 -0
- package/src/docs/docs/reference/plugins/astro-db.md +34 -0
- package/src/docs/docs/reference/plugins/astro-og-canvas.md +15 -0
- package/src/docs/docs/reference/plugins/astro.md +44 -0
- package/src/docs/docs/reference/plugins/ava.md +46 -0
- package/src/docs/docs/reference/plugins/babel.md +41 -0
- package/src/docs/docs/reference/plugins/biome.md +34 -0
- package/src/docs/docs/reference/plugins/bumpp.md +41 -0
- package/src/docs/docs/reference/plugins/bun.md +34 -0
- package/src/docs/docs/reference/plugins/c8.md +29 -0
- package/src/docs/docs/reference/plugins/capacitor.md +36 -0
- package/src/docs/docs/reference/plugins/changelogen.md +41 -0
- package/src/docs/docs/reference/plugins/changelogithub.md +41 -0
- package/src/docs/docs/reference/plugins/changesets.md +34 -0
- package/src/docs/docs/reference/plugins/commitizen.md +34 -0
- package/src/docs/docs/reference/plugins/commitlint.md +42 -0
- package/src/docs/docs/reference/plugins/convex.md +34 -0
- package/src/docs/docs/reference/plugins/create-typescript-app.md +34 -0
- package/src/docs/docs/reference/plugins/cspell.md +39 -0
- package/src/docs/docs/reference/plugins/cucumber.md +35 -0
- package/src/docs/docs/reference/plugins/cypress.md +41 -0
- package/src/docs/docs/reference/plugins/danger.md +34 -0
- package/src/docs/docs/reference/plugins/dependency-cruiser.md +46 -0
- package/src/docs/docs/reference/plugins/docusaurus.md +40 -0
- package/src/docs/docs/reference/plugins/dotenv.md +32 -0
- package/src/docs/docs/reference/plugins/drizzle.md +34 -0
- package/src/docs/docs/reference/plugins/eleventy.md +35 -0
- package/src/docs/docs/reference/plugins/eslint.md +86 -0
- package/src/docs/docs/reference/plugins/execa.md +15 -0
- package/src/docs/docs/reference/plugins/expo.md +35 -0
- package/src/docs/docs/reference/plugins/expressive-code.md +40 -0
- package/src/docs/docs/reference/plugins/gatsby.md +49 -0
- package/src/docs/docs/reference/plugins/github-action.md +34 -0
- package/src/docs/docs/reference/plugins/github-actions.md +34 -0
- package/src/docs/docs/reference/plugins/glob.md +29 -0
- package/src/docs/docs/reference/plugins/graphql-codegen.md +46 -0
- package/src/docs/docs/reference/plugins/hardhat.md +34 -0
- package/src/docs/docs/reference/plugins/husky.md +40 -0
- package/src/docs/docs/reference/plugins/i18next-parser.md +46 -0
- package/src/docs/docs/reference/plugins/jest.md +51 -0
- package/src/docs/docs/reference/plugins/karma.md +39 -0
- package/src/docs/docs/reference/plugins/knex.md +34 -0
- package/src/docs/docs/reference/plugins/ladle.md +39 -0
- package/src/docs/docs/reference/plugins/lefthook.md +46 -0
- package/src/docs/docs/reference/plugins/lint-staged.md +48 -0
- package/src/docs/docs/reference/plugins/linthtml.md +41 -0
- package/src/docs/docs/reference/plugins/lockfile-lint.md +41 -0
- package/src/docs/docs/reference/plugins/lost-pixel.md +34 -0
- package/src/docs/docs/reference/plugins/markdownlint.md +34 -0
- package/src/docs/docs/reference/plugins/mdx.md +38 -0
- package/src/docs/docs/reference/plugins/mdxlint.md +38 -0
- package/src/docs/docs/reference/plugins/metro.md +46 -0
- package/src/docs/docs/reference/plugins/mocha.md +47 -0
- package/src/docs/docs/reference/plugins/moonrepo.md +34 -0
- package/src/docs/docs/reference/plugins/msw.md +35 -0
- package/src/docs/docs/reference/plugins/nano-staged.md +39 -0
- package/src/docs/docs/reference/plugins/nest.md +36 -0
- package/src/docs/docs/reference/plugins/netlify.md +41 -0
- package/src/docs/docs/reference/plugins/next-intl.md +34 -0
- package/src/docs/docs/reference/plugins/next-mdx.md +35 -0
- package/src/docs/docs/reference/plugins/next.md +52 -0
- package/src/docs/docs/reference/plugins/nitro.md +52 -0
- package/src/docs/docs/reference/plugins/node-modules-inspector.md +49 -0
- package/src/docs/docs/reference/plugins/node.md +50 -0
- package/src/docs/docs/reference/plugins/nodemon.md +30 -0
- package/src/docs/docs/reference/plugins/npm-package-json-lint.md +41 -0
- package/src/docs/docs/reference/plugins/nuxt.md +55 -0
- package/src/docs/docs/reference/plugins/nx.md +62 -0
- package/src/docs/docs/reference/plugins/nyc.md +39 -0
- package/src/docs/docs/reference/plugins/oclif.md +34 -0
- package/src/docs/docs/reference/plugins/openapi-ts.md +41 -0
- package/src/docs/docs/reference/plugins/oxfmt.md +46 -0
- package/src/docs/docs/reference/plugins/oxlint.md +46 -0
- package/src/docs/docs/reference/plugins/parcel.md +38 -0
- package/src/docs/docs/reference/plugins/payload.md +40 -0
- package/src/docs/docs/reference/plugins/playwright-ct.md +40 -0
- package/src/docs/docs/reference/plugins/playwright-test.md +29 -0
- package/src/docs/docs/reference/plugins/playwright.md +49 -0
- package/src/docs/docs/reference/plugins/plop.md +34 -0
- package/src/docs/docs/reference/plugins/pm2.md +37 -0
- package/src/docs/docs/reference/plugins/pnpm.md +34 -0
- package/src/docs/docs/reference/plugins/postcss.md +46 -0
- package/src/docs/docs/reference/plugins/preconstruct.md +34 -0
- package/src/docs/docs/reference/plugins/prettier.md +39 -0
- package/src/docs/docs/reference/plugins/prisma.md +62 -0
- package/src/docs/docs/reference/plugins/qwik.md +40 -0
- package/src/docs/docs/reference/plugins/raycast.md +34 -0
- package/src/docs/docs/reference/plugins/react-cosmos.md +40 -0
- package/src/docs/docs/reference/plugins/react-native.md +34 -0
- package/src/docs/docs/reference/plugins/react-router.md +37 -0
- package/src/docs/docs/reference/plugins/relay.md +53 -0
- package/src/docs/docs/reference/plugins/release-it.md +34 -0
- package/src/docs/docs/reference/plugins/remark.md +40 -0
- package/src/docs/docs/reference/plugins/remix.md +43 -0
- package/src/docs/docs/reference/plugins/rollup.md +49 -0
- package/src/docs/docs/reference/plugins/rsbuild.md +34 -0
- package/src/docs/docs/reference/plugins/rslib.md +34 -0
- package/src/docs/docs/reference/plugins/rspack.md +34 -0
- package/src/docs/docs/reference/plugins/rstest.md +34 -0
- package/src/docs/docs/reference/plugins/sanity.md +38 -0
- package/src/docs/docs/reference/plugins/semantic-release.md +41 -0
- package/src/docs/docs/reference/plugins/sentry.md +36 -0
- package/src/docs/docs/reference/plugins/simple-git-hooks.md +38 -0
- package/src/docs/docs/reference/plugins/size-limit.md +38 -0
- package/src/docs/docs/reference/plugins/sst.md +34 -0
- package/src/docs/docs/reference/plugins/starlight.md +34 -0
- package/src/docs/docs/reference/plugins/storybook.md +43 -0
- package/src/docs/docs/reference/plugins/stryker.md +34 -0
- package/src/docs/docs/reference/plugins/stylelint.md +41 -0
- package/src/docs/docs/reference/plugins/svelte.md +34 -0
- package/src/docs/docs/reference/plugins/sveltekit.md +34 -0
- package/src/docs/docs/reference/plugins/svgo.md +38 -0
- package/src/docs/docs/reference/plugins/svgr.md +43 -0
- package/src/docs/docs/reference/plugins/swc.md +34 -0
- package/src/docs/docs/reference/plugins/syncpack.md +41 -0
- package/src/docs/docs/reference/plugins/tailwind.md +34 -0
- package/src/docs/docs/reference/plugins/tanstack-router.md +47 -0
- package/src/docs/docs/reference/plugins/taskfile.md +43 -0
- package/src/docs/docs/reference/plugins/travis.md +34 -0
- package/src/docs/docs/reference/plugins/ts-node.md +30 -0
- package/src/docs/docs/reference/plugins/tsdown.md +46 -0
- package/src/docs/docs/reference/plugins/tsup.md +46 -0
- package/src/docs/docs/reference/plugins/tsx.md +48 -0
- package/src/docs/docs/reference/plugins/typedoc.md +53 -0
- package/src/docs/docs/reference/plugins/typescript.md +57 -0
- package/src/docs/docs/reference/plugins/unbuild.md +34 -0
- package/src/docs/docs/reference/plugins/unocss.md +39 -0
- package/src/docs/docs/reference/plugins/vercel-og.md +41 -0
- package/src/docs/docs/reference/plugins/vike.md +37 -0
- package/src/docs/docs/reference/plugins/vite.md +50 -0
- package/src/docs/docs/reference/plugins/vitepress.md +37 -0
- package/src/docs/docs/reference/plugins/vitest.md +72 -0
- package/src/docs/docs/reference/plugins/vue.md +34 -0
- package/src/docs/docs/reference/plugins/webdriver-io.md +34 -0
- package/src/docs/docs/reference/plugins/webpack.md +55 -0
- package/src/docs/docs/reference/plugins/wireit.md +34 -0
- package/src/docs/docs/reference/plugins/wrangler.md +34 -0
- package/src/docs/docs/reference/plugins/xo.md +40 -0
- package/src/docs/docs/reference/plugins/yarn.md +35 -0
- package/src/docs/docs/reference/plugins/yorkie.md +34 -0
- package/src/docs/docs/reference/plugins/zx.md +15 -0
- package/src/docs/docs/typescript/unused-exports.md +7 -8
- package/src/docs/docs/writing-a-plugin/argument-parsing.md +1 -2
- package/src/docs/docs/writing-a-plugin/index.md +15 -36
|
@@ -23,72 +23,19 @@ exclude files from the analysis.
|
|
|
23
23
|
Read [configuring project files][1] for details and examples. Improving
|
|
24
24
|
configuration may have a significant impact on performance.
|
|
25
25
|
|
|
26
|
-
## Workspace sharing
|
|
27
|
-
|
|
28
|
-
Knip shares files from separate workspaces if the configuration in
|
|
29
|
-
`tsconfig.json` allows this. This aims to reduce memory consumption and run
|
|
30
|
-
duration. Relevant compiler options include `baseUrl`, `paths` and
|
|
31
|
-
`moduleResolution`.
|
|
32
|
-
|
|
33
|
-
With the `--debug` flag you can see how many programs Knip uses. Look for
|
|
34
|
-
messages like this:
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
...
|
|
38
|
-
[*] Installed 2 programs for 29 workspaces
|
|
39
|
-
...
|
|
40
|
-
[*] Analyzing used resolved files [P1/1] (123)
|
|
41
|
-
...
|
|
42
|
-
[*] Analyzing used resolved files [P1/2] (8)
|
|
43
|
-
...
|
|
44
|
-
[*] Analyzing used resolved files [P2/1] (41)
|
|
45
|
-
...
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
The first number in `P1/1` is the number of the programs, the second number
|
|
49
|
-
indicates additional entry files were found so it does another round of analysis
|
|
50
|
-
on those files.
|
|
51
|
-
|
|
52
|
-
Use [--isolate-workspaces][2] to disable this behavior. This is usually not
|
|
53
|
-
necessary, but more of an escape hatch in cases with memory usage issues or
|
|
54
|
-
incompatible `compilerOptions` across workspaces. Workspaces are analyzed
|
|
55
|
-
sequentially to spread out memory usage more evenly, which may prevent crashes
|
|
56
|
-
on large monorepos.
|
|
57
|
-
|
|
58
|
-
## Language Service
|
|
59
|
-
|
|
60
|
-
Knip does not install the TypeScript Language Service (LS) by default. This is
|
|
61
|
-
expensive, as TypeScript needs to set up symbols and caching for the rather slow
|
|
62
|
-
`findReferences` function. Even more so for multiple projects/workspaces.
|
|
63
|
-
|
|
64
|
-
There are two cases that enforce Knip to install the LS:
|
|
65
|
-
|
|
66
|
-
### 1. Class members
|
|
67
|
-
|
|
68
|
-
The `findReferences` function is used to find unused members of imported classes
|
|
69
|
-
(i.e. when the issue type `classMembers` is included).
|
|
70
|
-
|
|
71
|
-
### 2. Include external type definitions
|
|
72
|
-
|
|
73
|
-
When [`--include-libs`][3] is enabled, Knip loads type definitions of external
|
|
74
|
-
dependencies. This will also install the LS to access its `findReferences`
|
|
75
|
-
function. It acts as an extra line of defense: only exports that Knip thinks
|
|
76
|
-
aren't referenced (during the default/fast procedure), will now receive a second
|
|
77
|
-
opinion from `findReferences`.
|
|
78
|
-
|
|
79
26
|
## Metrics
|
|
80
27
|
|
|
81
|
-
Use [the `--performance` flag][
|
|
28
|
+
Use [the `--performance` flag][2] to see how many times potentially expensive
|
|
82
29
|
functions (e.g. `findReferences`) are invoked and how much time is spent in
|
|
83
30
|
those functions. Example usage:
|
|
84
31
|
|
|
85
32
|
```sh
|
|
86
|
-
knip --
|
|
33
|
+
knip --performance
|
|
87
34
|
```
|
|
88
35
|
|
|
89
36
|
## ignoreExportsUsedInFile
|
|
90
37
|
|
|
91
|
-
The [ignoreExportsUsedInFile][
|
|
38
|
+
The [ignoreExportsUsedInFile][3] option slows down the process slightly.
|
|
92
39
|
Typically, anywhere between 0.25% and 10% of total running time. To find out:
|
|
93
40
|
|
|
94
41
|
```sh
|
|
@@ -98,11 +45,9 @@ knip --performance-fn hasRefsInFile
|
|
|
98
45
|
## A last resort
|
|
99
46
|
|
|
100
47
|
In case Knip is unbearably slow (or even crashes), you could resort to [lint
|
|
101
|
-
individual workspaces][
|
|
48
|
+
individual workspaces][4].
|
|
102
49
|
|
|
103
50
|
[1]: ./configuring-project-files.md
|
|
104
|
-
[2]: ../reference/cli.md#--
|
|
105
|
-
[3]: ../
|
|
106
|
-
[4]: ../
|
|
107
|
-
[5]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
108
|
-
[6]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
51
|
+
[2]: ../reference/cli.md#--performance
|
|
52
|
+
[3]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
53
|
+
[4]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
package/src/docs/docs/index.mdx
CHANGED
|
@@ -3,7 +3,7 @@ title: Declutter your JavaScript & TypeScript projects
|
|
|
3
3
|
description: Project linter to find unused dependencies, exports and files
|
|
4
4
|
template: splash
|
|
5
5
|
hero:
|
|
6
|
-
title: Knip
|
|
6
|
+
title: Knip v6
|
|
7
7
|
tagline: Declutter your JavaScript & TypeScript projects
|
|
8
8
|
image:
|
|
9
9
|
file: ../../assets/logo.svg
|
|
@@ -12,8 +12,8 @@ hero:
|
|
|
12
12
|
link: ./overview/getting-started
|
|
13
13
|
icon: right-arrow
|
|
14
14
|
variant: primary
|
|
15
|
-
- text: 'NEW: Knip
|
|
16
|
-
link: /blog/
|
|
15
|
+
- text: 'NEW: Knip v6'
|
|
16
|
+
link: /blog/knip-v6
|
|
17
17
|
icon: rocket
|
|
18
18
|
variant: secondary
|
|
19
19
|
- text: View on GitHub
|
|
@@ -46,7 +46,7 @@ folder:
|
|
|
46
46
|
|
|
47
47
|
```json title="knip.json"
|
|
48
48
|
{
|
|
49
|
-
"$schema": "https://unpkg.com/knip@
|
|
49
|
+
"$schema": "https://unpkg.com/knip@6/schema.json",
|
|
50
50
|
"entry": ["src/index.ts", "scripts/{build,create}.js"],
|
|
51
51
|
"project": ["src/**/*.ts", "scripts/**/*.js"]
|
|
52
52
|
}
|
|
@@ -8,7 +8,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
|
|
|
8
8
|
|
|
9
9
|
## Requirements
|
|
10
10
|
|
|
11
|
-
Knip
|
|
11
|
+
Knip v6 requires at least Node.js v20.19.0. Or Bun.
|
|
12
12
|
|
|
13
13
|
Want to try Knip without installation? Visit [the playground][1].
|
|
14
14
|
|
|
@@ -99,24 +99,6 @@ knip --include-entry-exports
|
|
|
99
99
|
|
|
100
100
|
Also see [includeEntryExports][5].
|
|
101
101
|
|
|
102
|
-
### `--include-libs`
|
|
103
|
-
|
|
104
|
-
Getting false positives for exports consumed by external libraries? Try the
|
|
105
|
-
`--include-libs` flag:
|
|
106
|
-
|
|
107
|
-
```sh
|
|
108
|
-
knip --include-libs
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Also see [external libs][6].
|
|
112
|
-
|
|
113
|
-
### `--isolate-workspaces`
|
|
114
|
-
|
|
115
|
-
By default, Knip optimizes performance using [workspace sharing][7] to existing
|
|
116
|
-
TypeScript programs, based on the compatibility of their `compilerOptions`. This
|
|
117
|
-
flag disables this behavior and creates one program per workspace, which is
|
|
118
|
-
slower but memory usage is spread more evenly over time.
|
|
119
|
-
|
|
120
102
|
### `--no-gitignore`
|
|
121
103
|
|
|
122
104
|
Ignore `.gitignore` files.
|
|
@@ -131,14 +113,14 @@ Lint only production source files. This excludes:
|
|
|
131
113
|
- Storybook stories
|
|
132
114
|
- `devDependencies` from `package.json`
|
|
133
115
|
|
|
134
|
-
Read more at [Production Mode][
|
|
116
|
+
Read more at [Production Mode][6].
|
|
135
117
|
|
|
136
118
|
### `--strict`
|
|
137
119
|
|
|
138
120
|
Isolate workspaces and consider only direct dependencies. Implies [production
|
|
139
|
-
mode][
|
|
121
|
+
mode][7].
|
|
140
122
|
|
|
141
|
-
Read more at [Production Mode][
|
|
123
|
+
Read more at [Production Mode][6].
|
|
142
124
|
|
|
143
125
|
### `--watch`
|
|
144
126
|
|
|
@@ -157,7 +139,7 @@ workspaces). The default behavior is to lint all configured workspaces.
|
|
|
157
139
|
|
|
158
140
|
Shortcut: `-W`
|
|
159
141
|
|
|
160
|
-
See [filter workspaces][
|
|
142
|
+
See [filter workspaces][8] for more details and examples.
|
|
161
143
|
|
|
162
144
|
### `--directory [dir]`
|
|
163
145
|
|
|
@@ -172,8 +154,7 @@ Exclude provided issue types from report. Can be comma-separated or repeated.
|
|
|
172
154
|
Example:
|
|
173
155
|
|
|
174
156
|
```sh
|
|
175
|
-
knip --exclude
|
|
176
|
-
knip --exclude classMembers --exclude enumMembers
|
|
157
|
+
knip --exclude enumMembers
|
|
177
158
|
```
|
|
178
159
|
|
|
179
160
|
### `--include`
|
|
@@ -187,7 +168,7 @@ knip --include files,dependencies
|
|
|
187
168
|
knip --include files --include dependencies
|
|
188
169
|
```
|
|
189
170
|
|
|
190
|
-
Available [issue types][
|
|
171
|
+
Available [issue types][9] when filtering output using `--include` or
|
|
191
172
|
`--exclude`:
|
|
192
173
|
|
|
193
174
|
- `files`
|
|
@@ -196,10 +177,10 @@ Available [issue types][11] when filtering output using `--include` or
|
|
|
196
177
|
- `unresolved`
|
|
197
178
|
- `exports`
|
|
198
179
|
- `nsExports`
|
|
199
|
-
- `classMembers`
|
|
200
180
|
- `types`
|
|
201
181
|
- `nsTypes`
|
|
202
182
|
- `enumMembers`
|
|
183
|
+
- `namespaceMembers`
|
|
203
184
|
- `duplicates`
|
|
204
185
|
- `catalog`
|
|
205
186
|
|
|
@@ -216,7 +197,7 @@ Shortcut to include all types of dependency issues:
|
|
|
216
197
|
Shortcut to include all types of export issues:
|
|
217
198
|
|
|
218
199
|
```sh
|
|
219
|
-
--include exports,nsExports,
|
|
200
|
+
--include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates
|
|
220
201
|
```
|
|
221
202
|
|
|
222
203
|
### `--files`
|
|
@@ -251,7 +232,7 @@ knip --tags=+custom
|
|
|
251
232
|
```
|
|
252
233
|
|
|
253
234
|
This way, you can either focus on or ignore specific tagged exports with tags
|
|
254
|
-
you define yourself. This also works for individual
|
|
235
|
+
you define yourself. This also works for individual enum and namespace members.
|
|
255
236
|
|
|
256
237
|
The default directive is `+` (include) and the `@` prefix is ignored, so the
|
|
257
238
|
notation below is valid and will report only exports tagged `@lintignore` or
|
|
@@ -265,13 +246,13 @@ knip --tags @lintignore --tags @internal
|
|
|
265
246
|
|
|
266
247
|
### `--fix`
|
|
267
248
|
|
|
268
|
-
Read more at [auto-fix][
|
|
249
|
+
Read more at [auto-fix][10].
|
|
269
250
|
|
|
270
251
|
### `--fix-type`
|
|
271
252
|
|
|
272
253
|
Fix only issues of type, can be comma-separated or repeated.
|
|
273
254
|
|
|
274
|
-
More info about fixable types at [issue types][
|
|
255
|
+
More info about fixable types at [issue types][9]
|
|
275
256
|
|
|
276
257
|
### `--allow-remove-files`
|
|
277
258
|
|
|
@@ -285,7 +266,7 @@ Format modified files after `--fix` using the local formatter.
|
|
|
285
266
|
|
|
286
267
|
### `--preprocessor [preprocessor]`
|
|
287
268
|
|
|
288
|
-
Preprocess the results before providing it to the [reporter(s)][
|
|
269
|
+
Preprocess the results before providing it to the [reporter(s)][11].
|
|
289
270
|
|
|
290
271
|
Can be repeated. Examples:
|
|
291
272
|
|
|
@@ -297,7 +278,7 @@ knip --preprocessor ./my-preprocessor.ts
|
|
|
297
278
|
knip --preprocessor preprocessor-package
|
|
298
279
|
```
|
|
299
280
|
|
|
300
|
-
Also see [Reporters & Preprocessors][
|
|
281
|
+
Also see [Reporters & Preprocessors][12].
|
|
301
282
|
|
|
302
283
|
### `--preprocessor-options [json]`
|
|
303
284
|
|
|
@@ -326,7 +307,7 @@ Can be repeated. Example:
|
|
|
326
307
|
knip --reporter compact
|
|
327
308
|
```
|
|
328
309
|
|
|
329
|
-
Also see [Reporters & Preprocessors][
|
|
310
|
+
Also see [Reporters & Preprocessors][12].
|
|
330
311
|
|
|
331
312
|
### `--reporter-options [json]`
|
|
332
313
|
|
|
@@ -372,7 +353,7 @@ The default exit codes:
|
|
|
372
353
|
|
|
373
354
|
Shortcut: `-d`
|
|
374
355
|
|
|
375
|
-
Show [debug output][
|
|
356
|
+
Show [debug output][13].
|
|
376
357
|
|
|
377
358
|
### `--memory`
|
|
378
359
|
|
|
@@ -402,9 +383,6 @@ knip --memory
|
|
|
402
383
|
Total running time: 4.3s
|
|
403
384
|
```
|
|
404
385
|
|
|
405
|
-
Can be used with [--isolate-workspaces][16] to see the difference in garbage
|
|
406
|
-
collection during the process.
|
|
407
|
-
|
|
408
386
|
### `--memory-realtime`
|
|
409
387
|
|
|
410
388
|
Use this if Knip crashes to still see memory usage info over time:
|
|
@@ -452,7 +430,7 @@ Total running time: 5s
|
|
|
452
430
|
- `sum` the accumulated time of all invocations
|
|
453
431
|
|
|
454
432
|
This is not yet available in Bun, since it does not support
|
|
455
|
-
`performance.timerify` ([GitHub issue][
|
|
433
|
+
`performance.timerify` ([GitHub issue][14]).
|
|
456
434
|
|
|
457
435
|
### `--performance-fn`
|
|
458
436
|
|
|
@@ -475,37 +453,34 @@ Total running time: 12.9s
|
|
|
475
453
|
|
|
476
454
|
Trace exports to see where they are imported.
|
|
477
455
|
|
|
478
|
-
Also see [Trace][
|
|
456
|
+
Also see [Trace][15].
|
|
479
457
|
|
|
480
458
|
### `--trace-dependency [name]`
|
|
481
459
|
|
|
482
460
|
Trace package or binary name to see where it's referenced. Implies
|
|
483
|
-
[--trace][
|
|
461
|
+
[--trace][16].
|
|
484
462
|
|
|
485
463
|
### `--trace-export [name]`
|
|
486
464
|
|
|
487
|
-
Trace export name to see where it's imported. Implies [--trace][
|
|
465
|
+
Trace export name to see where it's imported. Implies [--trace][16].
|
|
488
466
|
|
|
489
467
|
### `--trace-file [path]`
|
|
490
468
|
|
|
491
|
-
Trace file to see where its exports are imported. Implies [--trace][
|
|
469
|
+
Trace file to see where its exports are imported. Implies [--trace][16].
|
|
492
470
|
|
|
493
471
|
[1]: https://bun.sh
|
|
494
472
|
[2]: ../reference/known-issues.md
|
|
495
473
|
[3]: https://no-color.org/
|
|
496
474
|
[4]: https://www.npmjs.com/package/picocolors
|
|
497
475
|
[5]: ./configuration.md#includeentryexports
|
|
498
|
-
[6]: ../
|
|
499
|
-
[7]:
|
|
500
|
-
[8]: ../features/
|
|
501
|
-
[9]:
|
|
502
|
-
[10]: ../features/
|
|
503
|
-
[11]:
|
|
504
|
-
[12]: ../features/
|
|
505
|
-
[13]:
|
|
506
|
-
[14]:
|
|
507
|
-
[15]: ../guides/troubleshooting.md#
|
|
508
|
-
[16]: #--
|
|
509
|
-
[17]: https://github.com/oven-sh/bun/issues/9271
|
|
510
|
-
[18]: ../guides/troubleshooting.md#trace
|
|
511
|
-
[19]: #--trace
|
|
476
|
+
[6]: ../features/production-mode.md
|
|
477
|
+
[7]: #--production
|
|
478
|
+
[8]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
479
|
+
[9]: ./issue-types.md
|
|
480
|
+
[10]: ../features/auto-fix.mdx
|
|
481
|
+
[11]: #--reporter-reporter
|
|
482
|
+
[12]: ../features/reporters.md
|
|
483
|
+
[13]: ../guides/troubleshooting.md#debug
|
|
484
|
+
[14]: https://github.com/oven-sh/bun/issues/9271
|
|
485
|
+
[15]: ../guides/troubleshooting.md#trace
|
|
486
|
+
[16]: #--trace
|
|
@@ -16,7 +16,7 @@ In JSON, use the provided JSON schema:
|
|
|
16
16
|
|
|
17
17
|
```json title="knip.json"
|
|
18
18
|
{
|
|
19
|
-
"$schema": "https://unpkg.com/knip@
|
|
19
|
+
"$schema": "https://unpkg.com/knip@6/schema.json"
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -26,7 +26,7 @@ In JSONC, use the provided JSONC schema:
|
|
|
26
26
|
|
|
27
27
|
```json title="knip.jsonc"
|
|
28
28
|
{
|
|
29
|
-
"$schema": "https://unpkg.com/knip@
|
|
29
|
+
"$schema": "https://unpkg.com/knip@6/schema-jsonc.json"
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -168,7 +168,7 @@ like so:
|
|
|
168
168
|
```
|
|
169
169
|
|
|
170
170
|
This way, you can either focus on or ignore specific tagged exports with tags
|
|
171
|
-
you define yourself. This also works for individual
|
|
171
|
+
you define yourself. This also works for individual enum and namespace members.
|
|
172
172
|
|
|
173
173
|
The default directive is `+` (include) and the `@` prefix is ignored, so the
|
|
174
174
|
notation below is valid and will report only exports tagged `@lintignore` or
|
|
@@ -288,8 +288,8 @@ Also see [Unused dependencies][11].
|
|
|
288
288
|
|
|
289
289
|
### `ignoreMembers`
|
|
290
290
|
|
|
291
|
-
Array of
|
|
292
|
-
allowed. Example:
|
|
291
|
+
Array of enum and namespace members to exclude from the report. Regular
|
|
292
|
+
expressions allowed. Example:
|
|
293
293
|
|
|
294
294
|
```json title="knip.json"
|
|
295
295
|
{
|
|
@@ -347,7 +347,7 @@ reporting other issues in those same files.
|
|
|
347
347
|
{
|
|
348
348
|
"ignoreIssues": {
|
|
349
349
|
"src/generated/**": ["exports", "types"],
|
|
350
|
-
"**/*.generated.ts": ["exports", "
|
|
350
|
+
"**/*.generated.ts": ["exports", "enumMembers", "namespaceMembers"]
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
```
|
|
@@ -394,7 +394,7 @@ If enabled, Knip will report unused exports in entry source files. But not in
|
|
|
394
394
|
entry and configuration files as configured by plugins, such as `next.config.js`
|
|
395
395
|
or `src/routes/+page.svelte`.
|
|
396
396
|
|
|
397
|
-
This will also enable reporting unused members of exported
|
|
397
|
+
This will also enable reporting unused members of exported enums and namespaces.
|
|
398
398
|
|
|
399
399
|
Set this option at root level to enable this globally, or within workspace
|
|
400
400
|
configurations individually.
|
|
@@ -144,13 +144,13 @@ imports of internal modules or external dependencies, and so on.
|
|
|
144
144
|
Even though a modular approach has its merits, for Knip it makes sense to have
|
|
145
145
|
all the pieces in a single tool.
|
|
146
146
|
|
|
147
|
-
Building up the module and dependency graphs requires
|
|
147
|
+
Building up the module and dependency graphs requires more than standard module
|
|
148
148
|
resolution and not only static but also dynamic analysis (i.e. actually load and
|
|
149
149
|
execute modules), such as for parsers of plugins to receive the exported value
|
|
150
150
|
of dynamic tooling configuration files. Additionally, [exports consumed by
|
|
151
|
-
external libraries][8] require type information
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
external libraries][8] require type information. Last but not least, shell
|
|
152
|
+
script parsing is required to find the right entry files, configuration files
|
|
153
|
+
and dependencies accurately.
|
|
154
154
|
|
|
155
155
|
The rippling effect of plugins and recursively adding entry files and
|
|
156
156
|
dependencies to build up the graphs is also exactly what's meant by
|
|
@@ -171,7 +171,7 @@ dependencies to build up the graphs is also exactly what's meant by
|
|
|
171
171
|
- Through scripts inside template strings in source files such as:
|
|
172
172
|
|
|
173
173
|
```ts
|
|
174
|
-
await $({ stdio:
|
|
174
|
+
await $({ stdio: "inherit" })`c8 node hydrate.js`; // execa
|
|
175
175
|
await $`node scripts/parse.js`; // bun/zx
|
|
176
176
|
```
|
|
177
177
|
|
|
@@ -207,14 +207,14 @@ in additional entry files recursively until no more entry files are found.
|
|
|
207
207
|
|
|
208
208
|
### What does Knip look for in source files?
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
oxc-parser is powerful and fault-tolerant. Knip visits all nodes of the
|
|
211
|
+
generated AST to find:
|
|
212
212
|
|
|
213
213
|
- Imports and dynamic imports of internal modules and external dependencies
|
|
214
214
|
- Exports
|
|
215
215
|
- Accessed properties on namespace imports and re-exports to track individual
|
|
216
216
|
export usage
|
|
217
|
-
- Calls to `require.resolve
|
|
217
|
+
- Calls to `require.resolve`, `import.meta.resolve` and more.
|
|
218
218
|
- Scripts in template strings (passed to [script parser][11])
|
|
219
219
|
|
|
220
220
|
### What's in the graphs?
|
|
@@ -232,10 +232,11 @@ required to create the report including all issue types:
|
|
|
232
232
|
- Unused exports
|
|
233
233
|
- Unused exported types
|
|
234
234
|
- Unused exported enum members
|
|
235
|
+
- Unused exported namespace members
|
|
235
236
|
- Duplicate exports
|
|
236
237
|
|
|
237
238
|
And optionally more issue types like individual exports and exported types in
|
|
238
|
-
namespace imports
|
|
239
|
+
namespace imports.
|
|
239
240
|
|
|
240
241
|
The graphs allows to report more interesting details, such as:
|
|
241
242
|
|
|
@@ -249,11 +250,14 @@ The graphs allows to report more interesting details, such as:
|
|
|
249
250
|
|
|
250
251
|
Knip reads the `package.json` file of each dependency. Most of the information
|
|
251
252
|
required is in the lockfile as well, which would be more efficient. However,
|
|
252
|
-
|
|
253
|
+
lockfiles lack some data, including:
|
|
253
254
|
|
|
254
255
|
- It requires lockfile parsing for each lockfile format and version of each
|
|
255
256
|
package manager.
|
|
256
257
|
- The lockfile doesn't contain whether the package [has types included][12].
|
|
258
|
+
- The lockfile doesn't contain entry point fields (`main`, `module`, `exports`)
|
|
259
|
+
needed to resolve what a dependency actually exposes.
|
|
260
|
+
- The lockfile doesn't contain `bin` entries to determine installed binaries.
|
|
257
261
|
|
|
258
262
|
## Module Resolution
|
|
259
263
|
|
|
@@ -273,13 +277,10 @@ seem to meet all requirements to be usable on its own by Knip:
|
|
|
273
277
|
- Don't resolve to type definition paths like `module.d.ts` but source code at
|
|
274
278
|
`module.js`
|
|
275
279
|
|
|
276
|
-
A few strategies have been tried and tweaked, and Knip currently uses
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
Everything else is handled by `oxc-resolver` for things like [script
|
|
282
|
-
parsing][11] and resolving references to files in other workspaces.
|
|
280
|
+
A few strategies have been tried and tweaked, and Knip currently uses
|
|
281
|
+
[oxc-resolver][13] with customizations for extension aliases, path aliases and
|
|
282
|
+
TypeScript-style resolution. This covers module resolution across all
|
|
283
|
+
workspaces, [script parsing][11] and references to files in other workspaces.
|
|
283
284
|
|
|
284
285
|
### How does Knip handle non-standard import syntax?
|
|
285
286
|
|
|
@@ -288,8 +289,8 @@ webpack loaders or Vite asset imports. Knip strips off the prefixes and suffixes
|
|
|
288
289
|
in import specifiers like this:
|
|
289
290
|
|
|
290
291
|
```ts title="component.ts"
|
|
291
|
-
import Icon from
|
|
292
|
-
import Styles from
|
|
292
|
+
import Icon from "./icon.svg?raw";
|
|
293
|
+
import Styles from "-!style-loader!css-loader?modules!./styles.css";
|
|
293
294
|
```
|
|
294
295
|
|
|
295
296
|
In this example, the `style-loader` and `css-loader` dependencies should be
|
|
@@ -307,10 +308,8 @@ perspective), it can be added as a workspace to the Knip configuration.
|
|
|
307
308
|
Projects - in the context of TypeScript - are directories with a `tsconfig.json`
|
|
308
309
|
file. They're not a concept in Knip.
|
|
309
310
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
utilizes [workspace sharing][14]. That's why debug output contains messages like
|
|
313
|
-
"Installed 2 programs for 29 workspaces".
|
|
311
|
+
Knip analyzes all workspaces using a single module graph with a shared module
|
|
312
|
+
resolver.
|
|
314
313
|
|
|
315
314
|
### Why doesn't Knip match my TypeScript project structure?
|
|
316
315
|
|
|
@@ -332,32 +331,22 @@ Note that any directory with a `package.json` not listed in the root
|
|
|
332
331
|
`package.json#workspaces` can be added to the Knip configuration manually to
|
|
333
332
|
have it handled as a separate workspace.
|
|
334
333
|
|
|
335
|
-
### Why doesn't Knip analyze workspaces in isolation by default?
|
|
336
|
-
|
|
337
|
-
Knip creates TypeScript programs to create a module graph and traverse file
|
|
338
|
-
ASTs. In a monorepo, it would make a lot of sense to create one program per
|
|
339
|
-
workspace. However, this slows down the whole process considerably. That's why
|
|
340
|
-
Knip shares the files of multiple workspaces in a single program if their
|
|
341
|
-
configuration allows it. This optimization is enabled by default, while it also
|
|
342
|
-
allows the module resolver (one per program) to do some more caching.
|
|
343
|
-
|
|
344
|
-
Also see [workspace sharing][14].
|
|
345
|
-
|
|
346
334
|
### Why doesn't Knip just use `ts.findReferences`?
|
|
347
335
|
|
|
348
336
|
TypeScript has a very good "Find references" feature, that you might be using in
|
|
349
|
-
your IDE as well.
|
|
350
|
-
its own module graph to look up export usages. Additional benefits for this
|
|
351
|
-
comprehensive graph include:
|
|
337
|
+
your IDE as well. There are a few reasons Knip doesn't use it:
|
|
352
338
|
|
|
353
|
-
-
|
|
354
|
-
|
|
355
|
-
-
|
|
339
|
+
- It requires the full TypeScript language service, which is heavy to
|
|
340
|
+
initialize.
|
|
341
|
+
- It must be called per symbol. A project with thousands of exports would need
|
|
342
|
+
thousands of calls, each scanning potentially all files. Knip parses each file
|
|
343
|
+
once and resolves all export usages from the resulting graph.
|
|
344
|
+
- It operates within a single TypeScript program. Monorepos with multiple
|
|
345
|
+
`tsconfig.json` files would need separate language service instances.
|
|
346
|
+
- It cannot see into non-standard files like `.vue`, `.svelte` and `.astro`.
|
|
356
347
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
included). In case analysis of exports requires type information of external
|
|
360
|
-
dependencies, the [`--include-libs ` flag][8] will trigger the same.
|
|
348
|
+
Knip's module graph is also serializable and cacheable, and usable for other
|
|
349
|
+
tools to build upon.
|
|
361
350
|
|
|
362
351
|
### Why can't I use path aliases to reference other workspaces?
|
|
363
352
|
|
|
@@ -369,19 +358,19 @@ The recommendation and best practice is to list such workspaces/dependencies in
|
|
|
369
358
|
`package.json`, and import them as such. Other tooling should not have any
|
|
370
359
|
issues with this standard approach either.
|
|
371
360
|
|
|
372
|
-
Also see the example in [TypeScript path aliases in monorepos][
|
|
361
|
+
Also see the example in [TypeScript path aliases in monorepos][14].
|
|
373
362
|
|
|
374
363
|
### What's up with that configurable `tsconfig.json` location?
|
|
375
364
|
|
|
376
365
|
There's a difference between `--tsConfig [file]` as a CLI argument and the
|
|
377
366
|
`typescript.config` option in Knip configuration.
|
|
378
367
|
|
|
379
|
-
The [`--tsConfig [file]` option][
|
|
368
|
+
The [`--tsConfig [file]` option][15] is used to provide an alternative location
|
|
380
369
|
for the default root `tsconfig.json` file. Relevant `compilerOptions` include
|
|
381
370
|
`paths` and `moduleResolution`. This setting is only available at the root
|
|
382
371
|
level.
|
|
383
372
|
|
|
384
|
-
On the other hand, the [`config` option of the plugin][
|
|
373
|
+
On the other hand, the [`config` option of the plugin][16] can be set per
|
|
385
374
|
workspace. The TypeScript plugin extracts referenced external dependencies such
|
|
386
375
|
as those in `extends`, `compilerOptions.types` and JSX settings:
|
|
387
376
|
|
|
@@ -405,7 +394,7 @@ From this example, Knip can determine whether the `@tsconfig/node20` and
|
|
|
405
394
|
for `tsconfig.json` can be set per workspace.
|
|
406
395
|
- In case path aliases from `compilerOptions.paths` aren't picked up by Knip,
|
|
407
396
|
either use `--tsConfig [file]` to target a different `tsconfig.json`, or
|
|
408
|
-
manually add [paths][
|
|
397
|
+
manually add [paths][17] to the Knip configuration. The latter can be done per
|
|
409
398
|
workspace.
|
|
410
399
|
|
|
411
400
|
## Compilers
|
|
@@ -418,17 +407,16 @@ than JavaScript and TypeScript modules should be included as well. For instance,
|
|
|
418
407
|
dependencies.
|
|
419
408
|
|
|
420
409
|
Knip includes basic "compilers" for a few common file types (Astro, MDX, Svelte,
|
|
421
|
-
Vue).
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
other file types.
|
|
410
|
+
Vue). These are lightweight regex-based extractors, not actual compilers. You
|
|
411
|
+
can override the built-in compilers with your project's actual compiler, and add
|
|
412
|
+
additional ones for other file types.
|
|
425
413
|
|
|
426
414
|
### Why are the exports of my `.vue` files not used?
|
|
427
415
|
|
|
428
416
|
Knip comes with basic "compilers" for a few common non-standard file types.
|
|
429
417
|
They're not actual compilers, they're regular expressions only to extract import
|
|
430
418
|
statements. Override the built-in Vue "compiler" with the real one in your
|
|
431
|
-
project. Also see the answer to the previous question and [Compilers][
|
|
419
|
+
project. Also see the answer to the previous question and [Compilers][18].
|
|
432
420
|
|
|
433
421
|
## Miscellaneous
|
|
434
422
|
|
|
@@ -464,12 +452,10 @@ Examples of features that have been requested include:
|
|
|
464
452
|
- Analyze workspaces in parallel
|
|
465
453
|
- Support Deno
|
|
466
454
|
- Improve internal code structures and accessibility to support contributions
|
|
467
|
-
- Replace dependencies for better performance and correctness, such as for shell
|
|
468
|
-
script parsing and globbing with "unignores".
|
|
469
455
|
|
|
470
456
|
These are all interesting ideas, but most increase the API surface area, and all
|
|
471
457
|
require more development efforts and maintenance. Time is limited and
|
|
472
|
-
[sponsorships][
|
|
458
|
+
[sponsorships][19] currently don't cover - this can change though!
|
|
473
459
|
|
|
474
460
|
[1]: ../reference/integrations.md#mcp-server
|
|
475
461
|
[2]: ../reference/integrations.md#vs-code-extension
|
|
@@ -484,10 +470,9 @@ require more development efforts and maintenance. Time is limited and
|
|
|
484
470
|
[11]: ../features/script-parser.md
|
|
485
471
|
[12]: ../guides/handling-issues.mdx#type-definition-packages
|
|
486
472
|
[13]: https://oxc.rs/docs/guide/usage/resolver.html
|
|
487
|
-
[14]: ../guides/
|
|
488
|
-
[15]: ../
|
|
489
|
-
[16]: ../
|
|
490
|
-
[17]: ../
|
|
491
|
-
[18]: ../
|
|
492
|
-
[19]:
|
|
493
|
-
[20]: /sponsors
|
|
473
|
+
[14]: ../guides/handling-issues.mdx#typescript-path-aliases-in-monorepos
|
|
474
|
+
[15]: ../reference/cli.md#--tsconfig-file
|
|
475
|
+
[16]: ../explanations/plugins.md#configuration-files
|
|
476
|
+
[17]: ../reference/configuration.md#paths
|
|
477
|
+
[18]: ../features/compilers.md
|
|
478
|
+
[19]: /sponsors
|
|
@@ -95,8 +95,7 @@ dependencies.
|
|
|
95
95
|
[7]: #vs-code-extension-screenshots
|
|
96
96
|
[8]: https://plugins.jetbrains.com/plugin/29765-knip
|
|
97
97
|
[9]: https://www.npmjs.com/package/@knip/mcp
|
|
98
|
-
[10]:
|
|
99
|
-
https://github.com/webpro-nl/knip/blob/main/packages/language-server/README.md
|
|
98
|
+
[10]: https://github.com/webpro-nl/knip/blob/main/packages/language-server/README.md
|
|
100
99
|
[11]: /screenshots/editors-and-agents/diagnostics.webp
|
|
101
100
|
[12]: /screenshots/editors-and-agents/imports-exports.webp
|
|
102
101
|
[13]: /screenshots/editors-and-agents/circular-dependency.webp
|