@knip/mcp 0.0.16 → 0.0.18
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 +2 -2
- package/src/docs/docs/features/auto-fix.mdx +20 -5
- package/src/docs/docs/features/production-mode.md +1 -1
- package/src/docs/docs/features/reporters.md +9 -7
- package/src/docs/docs/guides/handling-issues.mdx +125 -109
- package/src/docs/docs/guides/issue-reproduction.md +11 -7
- package/src/docs/docs/guides/performance.md +19 -8
- package/src/docs/docs/guides/using-knip-in-ci.md +16 -20
- package/src/docs/docs/overview/features.md +2 -2
- package/src/docs/docs/overview/getting-started.mdx +6 -7
- package/src/docs/docs/reference/configuration-hints.md +146 -0
- package/src/docs/docs/reference/faq.md +26 -34
- package/src/docs/docs/reference/integrations.md +105 -0
- package/src/docs/docs/reference/known-issues.md +11 -7
- package/src/docs/docs/reference/plugins/angular.md +6 -10
- package/src/docs/docs/reference/plugins/astro-db.md +7 -10
- package/src/docs/docs/reference/plugins/astro-og-canvas.md +13 -0
- package/src/docs/docs/reference/plugins/astro.md +6 -10
- package/src/docs/docs/reference/plugins/ava.md +7 -10
- package/src/docs/docs/reference/plugins/babel.md +3 -9
- package/src/docs/docs/reference/plugins/biome.md +7 -10
- package/src/docs/docs/reference/plugins/bumpp.md +3 -9
- package/src/docs/docs/reference/plugins/bun.md +2 -6
- package/src/docs/docs/reference/plugins/c8.md +4 -7
- package/src/docs/docs/reference/plugins/capacitor.md +6 -10
- package/src/docs/docs/reference/plugins/changelogen.md +3 -9
- package/src/docs/docs/reference/plugins/changelogithub.md +3 -9
- package/src/docs/docs/reference/plugins/changesets.md +6 -10
- package/src/docs/docs/reference/plugins/commitizen.md +8 -10
- package/src/docs/docs/reference/plugins/commitlint.md +3 -9
- package/src/docs/docs/reference/plugins/convex.md +7 -10
- package/src/docs/docs/reference/plugins/create-typescript-app.md +6 -10
- package/src/docs/docs/reference/plugins/cspell.md +3 -9
- package/src/docs/docs/reference/plugins/cucumber.md +9 -11
- package/src/docs/docs/reference/plugins/cypress.md +6 -10
- package/src/docs/docs/reference/plugins/danger.md +6 -10
- package/src/docs/docs/reference/plugins/dependency-cruiser.md +9 -14
- package/src/docs/docs/reference/plugins/docusaurus.md +6 -10
- package/src/docs/docs/reference/plugins/dotenv.md +4 -8
- package/src/docs/docs/reference/plugins/drizzle.md +6 -10
- package/src/docs/docs/reference/plugins/eleventy.md +11 -11
- package/src/docs/docs/reference/plugins/eslint.md +10 -22
- package/src/docs/docs/reference/plugins/expo.md +11 -11
- package/src/docs/docs/reference/plugins/expressive-code.md +39 -0
- package/src/docs/docs/reference/plugins/gatsby.md +3 -9
- package/src/docs/docs/reference/plugins/github-action.md +6 -10
- package/src/docs/docs/reference/plugins/github-actions.md +7 -10
- package/src/docs/docs/reference/plugins/glob.md +4 -8
- package/src/docs/docs/reference/plugins/graphql-codegen.md +3 -9
- package/src/docs/docs/reference/plugins/hardhat.md +6 -10
- package/src/docs/docs/reference/plugins/husky.md +3 -9
- package/src/docs/docs/reference/plugins/i18next-parser.md +9 -14
- package/src/docs/docs/reference/plugins/jest.md +10 -14
- package/src/docs/docs/reference/plugins/karma.md +3 -9
- package/src/docs/docs/reference/plugins/knex.md +6 -10
- package/src/docs/docs/reference/plugins/ladle.md +9 -11
- package/src/docs/docs/reference/plugins/lefthook.md +3 -9
- package/src/docs/docs/reference/plugins/lint-staged.md +3 -9
- package/src/docs/docs/reference/plugins/linthtml.md +3 -9
- package/src/docs/docs/reference/plugins/lockfile-lint.md +3 -9
- package/src/docs/docs/reference/plugins/lost-pixel.md +6 -10
- package/src/docs/docs/reference/plugins/markdownlint.md +7 -10
- package/src/docs/docs/reference/plugins/mdx.md +6 -10
- package/src/docs/docs/reference/plugins/mdxlint.md +3 -9
- package/src/docs/docs/reference/plugins/metro.md +9 -12
- package/src/docs/docs/reference/plugins/mocha.md +13 -15
- package/src/docs/docs/reference/plugins/moonrepo.md +8 -10
- package/src/docs/docs/reference/plugins/msw.md +9 -11
- package/src/docs/docs/reference/plugins/nano-staged.md +3 -9
- package/src/docs/docs/reference/plugins/nest.md +9 -10
- package/src/docs/docs/reference/plugins/netlify.md +9 -11
- package/src/docs/docs/reference/plugins/next-intl.md +6 -10
- package/src/docs/docs/reference/plugins/next-mdx.md +9 -11
- package/src/docs/docs/reference/plugins/next.md +6 -10
- package/src/docs/docs/reference/plugins/nitro.md +50 -0
- package/src/docs/docs/reference/plugins/node-modules-inspector.md +4 -11
- package/src/docs/docs/reference/plugins/node.md +8 -12
- package/src/docs/docs/reference/plugins/nodemon.md +4 -8
- package/src/docs/docs/reference/plugins/npm-package-json-lint.md +3 -9
- package/src/docs/docs/reference/plugins/nuxt.md +8 -14
- package/src/docs/docs/reference/plugins/nx.md +7 -15
- package/src/docs/docs/reference/plugins/nyc.md +3 -9
- package/src/docs/docs/reference/plugins/oclif.md +6 -10
- package/src/docs/docs/reference/plugins/oxlint.md +9 -14
- package/src/docs/docs/reference/plugins/parcel.md +6 -10
- package/src/docs/docs/reference/plugins/playwright-ct.md +6 -10
- package/src/docs/docs/reference/plugins/playwright-test.md +5 -10
- package/src/docs/docs/reference/plugins/playwright.md +12 -15
- package/src/docs/docs/reference/plugins/plop.md +6 -10
- package/src/docs/docs/reference/plugins/pnpm.md +5 -8
- package/src/docs/docs/reference/plugins/postcss.md +3 -9
- package/src/docs/docs/reference/plugins/preconstruct.md +6 -10
- package/src/docs/docs/reference/plugins/prettier.md +3 -9
- package/src/docs/docs/reference/plugins/prisma.md +11 -15
- package/src/docs/docs/reference/plugins/react-cosmos.md +6 -10
- package/src/docs/docs/reference/plugins/react-router.md +3 -9
- package/src/docs/docs/reference/plugins/relay.md +10 -14
- package/src/docs/docs/reference/plugins/release-it.md +7 -10
- package/src/docs/docs/reference/plugins/remark.md +3 -9
- package/src/docs/docs/reference/plugins/remix.md +3 -9
- package/src/docs/docs/reference/plugins/rollup.md +9 -14
- package/src/docs/docs/reference/plugins/rsbuild.md +6 -10
- package/src/docs/docs/reference/plugins/rslib.md +6 -10
- package/src/docs/docs/reference/plugins/rspack.md +6 -10
- package/src/docs/docs/reference/plugins/rstest.md +6 -10
- package/src/docs/docs/reference/plugins/semantic-release.md +3 -9
- package/src/docs/docs/reference/plugins/sentry.md +6 -10
- package/src/docs/docs/reference/plugins/simple-git-hooks.md +3 -9
- package/src/docs/docs/reference/plugins/size-limit.md +4 -11
- package/src/docs/docs/reference/plugins/sst.md +6 -10
- package/src/docs/docs/reference/plugins/starlight.md +6 -10
- package/src/docs/docs/reference/plugins/storybook.md +9 -11
- package/src/docs/docs/reference/plugins/stryker.md +6 -10
- package/src/docs/docs/reference/plugins/stylelint.md +3 -9
- package/src/docs/docs/reference/plugins/svelte.md +4 -13
- package/src/docs/docs/reference/plugins/sveltekit.md +33 -0
- package/src/docs/docs/reference/plugins/svgo.md +6 -10
- package/src/docs/docs/reference/plugins/svgr.md +3 -9
- package/src/docs/docs/reference/plugins/swc.md +6 -10
- package/src/docs/docs/reference/plugins/syncpack.md +3 -9
- package/src/docs/docs/reference/plugins/tailwind.md +6 -10
- package/src/docs/docs/reference/plugins/tanstack-router.md +9 -10
- package/src/docs/docs/reference/plugins/taskfile.md +13 -10
- package/src/docs/docs/reference/plugins/travis.md +5 -8
- package/src/docs/docs/reference/plugins/ts-node.md +4 -8
- package/src/docs/docs/reference/plugins/tsdown.md +10 -14
- package/src/docs/docs/reference/plugins/tsup.md +10 -14
- package/src/docs/docs/reference/plugins/tsx.md +8 -12
- package/src/docs/docs/reference/plugins/typedoc.md +6 -13
- package/src/docs/docs/reference/plugins/typescript.md +10 -17
- package/src/docs/docs/reference/plugins/unbuild.md +6 -10
- package/src/docs/docs/reference/plugins/unocss.md +3 -9
- package/src/docs/docs/reference/plugins/vercel-og.md +3 -9
- package/src/docs/docs/reference/plugins/vike.md +3 -9
- package/src/docs/docs/reference/plugins/vite.md +9 -14
- package/src/docs/docs/reference/plugins/vitepress.md +3 -9
- package/src/docs/docs/reference/plugins/vitest.md +6 -13
- package/src/docs/docs/reference/plugins/vue.md +6 -10
- package/src/docs/docs/reference/plugins/webdriver-io.md +6 -10
- package/src/docs/docs/reference/plugins/webpack.md +9 -14
- package/src/docs/docs/reference/plugins/wireit.md +6 -10
- package/src/docs/docs/reference/plugins/wrangler.md +6 -10
- package/src/docs/docs/reference/plugins/xo.md +7 -10
- package/src/docs/docs/reference/plugins/yarn.md +5 -8
- package/src/docs/docs/reference/plugins/yorkie.md +6 -10
- package/src/docs/docs/reference/plugins.md +5 -1
- package/src/docs/docs/reference/related-tooling.md +3 -3
- package/src/docs/docs/sponsors.mdx +2 -2
- package/src/docs/docs/typescript/unused-exports.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knip/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Knip MCP Server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
30
30
|
"zod": "^4.1.11",
|
|
31
|
-
"knip": "^5.
|
|
31
|
+
"knip": "^5.83.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.18.0"
|
|
@@ -9,13 +9,13 @@ Run Knip as you normally would, and if the report looks good then run it again
|
|
|
9
9
|
with the `--fix` flag to let Knip automatically apply fixes. It fixes the
|
|
10
10
|
following [issue types][1]:
|
|
11
11
|
|
|
12
|
-
- Remove `export` keyword for unused exports and exported types
|
|
12
|
+
- Remove `export` keyword for unused exports, re-exports, and exported types
|
|
13
13
|
- Remove `export default` keywords for unused default exports
|
|
14
|
-
- Remove exports, re-exports and exported types
|
|
15
14
|
- Remove unused enum members
|
|
16
15
|
- Remove unused class members (disabled by default)
|
|
17
16
|
- Remove unused `dependencies` and `devDependencies` from `package.json`
|
|
18
17
|
- Remove unused files
|
|
18
|
+
- Remove unused catalog entries
|
|
19
19
|
|
|
20
20
|
:::caution
|
|
21
21
|
|
|
@@ -91,9 +91,9 @@ configuration in your project.
|
|
|
91
91
|
|
|
92
92
|
### 2. Unused variables
|
|
93
93
|
|
|
94
|
-
Use a tool like ESLint or Biome to find and remove unused variables
|
|
95
|
-
files. Even better, try [remove-unused-vars][3] to remove unused
|
|
96
|
-
within files.
|
|
94
|
+
Use a tool like ESLint or Biome to find and remove unused imports and variables
|
|
95
|
+
inside files. Even better, try [remove-unused-vars][3] to remove unused
|
|
96
|
+
variables within files.
|
|
97
97
|
|
|
98
98
|
This may result in more deleted code, and Knip may then find more unused code.
|
|
99
99
|
Rinse and repeat!
|
|
@@ -316,6 +316,20 @@ component are unused and will remove those.
|
|
|
316
316
|
|
|
317
317
|
Note that [`classMembers` aren't included by default][4].
|
|
318
318
|
|
|
319
|
+
### Catalog entries
|
|
320
|
+
|
|
321
|
+
Unused [catalog][5] entries are removed from `pnpm-workspace.yaml`:
|
|
322
|
+
|
|
323
|
+
```diff title="pnpm-workspace.yaml"
|
|
324
|
+
packages:
|
|
325
|
+
- 'packages/*'
|
|
326
|
+
catalog:
|
|
327
|
+
react: ^18.0.0
|
|
328
|
+
- unused-package: ^1.0.0
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Catalogs in `package.json` are supported as well.
|
|
332
|
+
|
|
319
333
|
## What's not included
|
|
320
334
|
|
|
321
335
|
Operations that auto-fix does not (yet) perform and why:
|
|
@@ -331,3 +345,4 @@ Operations that auto-fix does not (yet) perform and why:
|
|
|
331
345
|
[2]: https://github.com/JoshuaKGoldberg/formatly
|
|
332
346
|
[3]: https://github.com/webpro-nl/remove-unused-vars
|
|
333
347
|
[4]: ../guides/handling-issues.mdx#class-members
|
|
348
|
+
[5]: https://pnpm.io/catalogs
|
|
@@ -37,7 +37,7 @@ Here's what's included in production mode:
|
|
|
37
37
|
- Only `entry` and `project` patterns suffixed with `!`
|
|
38
38
|
- Only production `entry` file patterns exported by plugins (such as Next.js and
|
|
39
39
|
Remix)
|
|
40
|
-
- Only the `start`
|
|
40
|
+
- Only the `start` script (of `package.json#scripts`)
|
|
41
41
|
- Ignore exports with the [`@internal` tag][1]
|
|
42
42
|
|
|
43
43
|
:::note
|
|
@@ -79,16 +79,18 @@ The keys match the [reported issue types][6]. Example usage:
|
|
|
79
79
|
knip --reporter json
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
###
|
|
83
|
-
|
|
84
|
-
TODO
|
|
82
|
+
### GitHub Actions
|
|
85
83
|
|
|
84
|
+
Use the GitHub Actions reporter in a workflow for annotations in pull requests.
|
|
86
85
|
Example usage:
|
|
87
86
|
|
|
88
87
|
```sh
|
|
89
88
|
knip --reporter github-actions
|
|
90
89
|
```
|
|
91
90
|
|
|
91
|
+
Changed files in pull requests will now contain inline annotations for lint
|
|
92
|
+
findings.
|
|
93
|
+
|
|
92
94
|
### Markdown
|
|
93
95
|
|
|
94
96
|
The built-in `markdown` reporter output is meant to be saved to a Markdown file.
|
|
@@ -138,8 +140,8 @@ dangling.js
|
|
|
138
140
|
<summary>Unused dependencies (2)</summary>
|
|
139
141
|
|
|
140
142
|
```
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
my-package package.json:17:5
|
|
144
|
+
unused-dep package.json:20:5
|
|
143
145
|
```
|
|
144
146
|
|
|
145
147
|
</details>
|
|
@@ -162,8 +164,8 @@ dangling.js
|
|
|
162
164
|
<summary>Unused dependencies (2)</summary>
|
|
163
165
|
|
|
164
166
|
```
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
my-package package.json:17:5
|
|
168
|
+
unused-dep package.json:20:5
|
|
167
169
|
```
|
|
168
170
|
|
|
169
171
|
</details>
|
|
@@ -17,6 +17,13 @@ files will also reduce the number of unused dependencies.
|
|
|
17
17
|
3. [Unresolved imports][3]
|
|
18
18
|
4. [Unused exports][4]
|
|
19
19
|
|
|
20
|
+
:::tip
|
|
21
|
+
|
|
22
|
+
Try the [Knip Editor Extension][5]! Let your coding agent use the built-in
|
|
23
|
+
MCP Server and create a custom `knip.json` for you.
|
|
24
|
+
|
|
25
|
+
:::
|
|
26
|
+
|
|
20
27
|
## Unused files
|
|
21
28
|
|
|
22
29
|
Getting the list of unused files right trickles down into the other issue types
|
|
@@ -27,22 +34,29 @@ of `project` files, but not in the set of files resolved from the `entry` files:
|
|
|
27
34
|
unused files = project files - (entry files + resolved files)
|
|
28
35
|
```
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
:::tip
|
|
38
|
+
|
|
39
|
+
Addressing reported [Configuration Hints][6] first might help significantly,
|
|
40
|
+
especially when handling unused files.
|
|
41
|
+
|
|
42
|
+
:::
|
|
43
|
+
|
|
44
|
+
Common causes for unused files include:
|
|
31
45
|
|
|
32
|
-
- [Missing generated files][
|
|
33
|
-
- [Dynamic import specifiers][
|
|
34
|
-
- [Unsupported arguments in scripts][
|
|
35
|
-
- [Unsupported file formats][
|
|
36
|
-
- [Missing plugin][
|
|
37
|
-
- [Incomplete plugin][
|
|
38
|
-
- [TypeScript path aliases in monorepos][
|
|
39
|
-
- [Relative paths across workspaces][
|
|
40
|
-
- [Integrated monorepos][
|
|
41
|
-
- [Auto-mocking or auto-imports][
|
|
46
|
+
- [Missing generated files][7]
|
|
47
|
+
- [Dynamic import specifiers][8]
|
|
48
|
+
- [Unsupported arguments in scripts][9]
|
|
49
|
+
- [Unsupported file formats][10]
|
|
50
|
+
- [Missing plugin][11]
|
|
51
|
+
- [Incomplete plugin][12]
|
|
52
|
+
- [TypeScript path aliases in monorepos][13]
|
|
53
|
+
- [Relative paths across workspaces][14]
|
|
54
|
+
- [Integrated monorepos][15]
|
|
55
|
+
- [Auto-mocking or auto-imports][16]
|
|
42
56
|
|
|
43
57
|
In most cases you can add `entry` patterns manually.
|
|
44
58
|
|
|
45
|
-
Use `--files` to [filter the report][
|
|
59
|
+
Use `--files` to [filter the report][17] and focus only on unused files:
|
|
46
60
|
|
|
47
61
|
```sh
|
|
48
62
|
knip --files
|
|
@@ -55,15 +69,15 @@ exports.
|
|
|
55
69
|
:::caution
|
|
56
70
|
|
|
57
71
|
Don't add unused files to the `ignore` option before reading [configuring
|
|
58
|
-
project files][
|
|
59
|
-
mode and `ignore
|
|
72
|
+
project files][18]. Learn why and when to use `entry`, `project`, production
|
|
73
|
+
mode and `ignore*` patterns for better results and performance.
|
|
60
74
|
|
|
61
75
|
:::
|
|
62
76
|
|
|
63
77
|
### Missing generated files
|
|
64
78
|
|
|
65
79
|
For certain features, Knip needs to run after relevant files are generated. For
|
|
66
|
-
instance, [source mapping][
|
|
80
|
+
instance, [source mapping][19] in a monorepo may require files to be built into
|
|
67
81
|
`dist` folders first. And generated files in the `src` directory may import
|
|
68
82
|
other files. For instance, the `src/routeTree.gen.ts` file generated by
|
|
69
83
|
`@tanstack/router` must exist so Knip can find the imported route files.
|
|
@@ -101,7 +115,7 @@ Some tooling command arguments aren't recognized:
|
|
|
101
115
|
**Solution**: add `production.ts` to `entry` patterns.
|
|
102
116
|
|
|
103
117
|
This works the same for any script, also those in GitHub Actions workflows or
|
|
104
|
-
Git hooks. See [script parser][
|
|
118
|
+
Git hooks. See [script parser][20] for more details about Knip's script parser.
|
|
105
119
|
|
|
106
120
|
### Unsupported file formats
|
|
107
121
|
|
|
@@ -118,7 +132,7 @@ Entry files referenced in HTML files (e.g. `<script src="production.js">`).
|
|
|
118
132
|
**Solution**: add `production.js` to `entry` patterns. Or add an `.html`
|
|
119
133
|
compiler to extract and resolve the value of `<script src>` elements.
|
|
120
134
|
|
|
121
|
-
Knip has support for some popular framework formats through [compilers][
|
|
135
|
+
Knip has support for some popular framework formats through [compilers][21], and
|
|
122
136
|
additional compilers can be added for any file type. The recommended solution is
|
|
123
137
|
usually to add the file as shown in each example as an `entry` file.
|
|
124
138
|
|
|
@@ -134,16 +148,16 @@ examples:
|
|
|
134
148
|
- A framework automatically imports all files matching `src/models/*.ts` → those
|
|
135
149
|
files are reported as unused.
|
|
136
150
|
|
|
137
|
-
**Solution**: [create a new plugin][
|
|
138
|
-
the list][
|
|
139
|
-
dependency or two (using [`ignoreDependencies`][
|
|
151
|
+
**Solution**: [create a new plugin][22] for the tool or framework that's not [in
|
|
152
|
+
the list][23] yet. Or work around it and add `entry` patterns and maybe ignore a
|
|
153
|
+
dependency or two (using [`ignoreDependencies`][24]).
|
|
140
154
|
|
|
141
155
|
### Incomplete plugin
|
|
142
156
|
|
|
143
157
|
Files may be reported as unused if existing plugins do not include that entry
|
|
144
|
-
file pattern yet. See the [plugins section of entry files][
|
|
158
|
+
file pattern yet. See the [plugins section of entry files][25] for more details.
|
|
145
159
|
|
|
146
|
-
**Solution**: [override plugin configuration][
|
|
160
|
+
**Solution**: [override plugin configuration][26] to customize default patterns
|
|
147
161
|
for existing plugins. Or even better: send a pull request to improve the plugin.
|
|
148
162
|
|
|
149
163
|
### TypeScript path aliases in monorepos
|
|
@@ -179,7 +193,7 @@ Knip, it's better to be explicit and list other workspaces as dependencies in
|
|
|
179
193
|
An additional benefit is that Knip will report unused and unlisted dependencies
|
|
180
194
|
from now on.
|
|
181
195
|
|
|
182
|
-
Also see [FAQ: Why can't I use path aliases to reference other workspaces?][
|
|
196
|
+
Also see [FAQ: Why can't I use path aliases to reference other workspaces?][27]
|
|
183
197
|
|
|
184
198
|
### Relative paths across workspaces
|
|
185
199
|
|
|
@@ -202,7 +216,7 @@ import { something } from '@org/common';
|
|
|
202
216
|
An additional benefit is that Knip will report unused and unlisted dependencies
|
|
203
217
|
from now on.
|
|
204
218
|
|
|
205
|
-
Also see [TypeScript path aliases in monorepos][
|
|
219
|
+
Also see [TypeScript path aliases in monorepos][13].
|
|
206
220
|
|
|
207
221
|
### Integrated monorepos
|
|
208
222
|
|
|
@@ -210,7 +224,7 @@ Multiple instances of configuration files like `.eslintrc` and
|
|
|
210
224
|
`jest.config.json` across the repository may be reported as unused when working
|
|
211
225
|
in a (mono)repo with a single `package.json`.
|
|
212
226
|
|
|
213
|
-
**Solution**: see [integrated monorepos][
|
|
227
|
+
**Solution**: see [integrated monorepos][28] for more details and how to
|
|
214
228
|
configure plugins to target those configuration files.
|
|
215
229
|
|
|
216
230
|
### Auto-mocking or auto-imports
|
|
@@ -245,12 +259,12 @@ unused dependencies.
|
|
|
245
259
|
|
|
246
260
|
The most common causes for unused dependencies include:
|
|
247
261
|
|
|
248
|
-
- [Missing or incomplete plugins][
|
|
249
|
-
- [Unrecognized references][
|
|
250
|
-
- [Type Definition Packages][
|
|
251
|
-
- [Dependencies named after Node.js builtins][
|
|
262
|
+
- [Missing or incomplete plugins][29]
|
|
263
|
+
- [Unrecognized references][30]
|
|
264
|
+
- [Type Definition Packages][31]
|
|
265
|
+
- [Dependencies named after Node.js builtins][32]
|
|
252
266
|
|
|
253
|
-
Use `--dependencies` to [filter the report][
|
|
267
|
+
Use `--dependencies` to [filter the report][17] and focus only on issues related
|
|
254
268
|
to dependencies:
|
|
255
269
|
|
|
256
270
|
```sh
|
|
@@ -281,10 +295,10 @@ Sometimes a reference to a dependency is unrecognizable or unreachable to Knip,
|
|
|
281
295
|
so it's a false positive and incorrectly reported as unused.
|
|
282
296
|
|
|
283
297
|
**Solution**: add a new plugin or improve an existing one. If you don't feel
|
|
284
|
-
like a plugin could solve it, a last resort is to use [ignoreDependencies][
|
|
298
|
+
like a plugin could solve it, a last resort is to use [ignoreDependencies][24].
|
|
285
299
|
|
|
286
300
|
If a binary (or "executable") is referenced you'll want to use `ignoreBinaries`
|
|
287
|
-
instead. See [unlisted binaries][
|
|
301
|
+
instead. See [unlisted binaries][33].
|
|
288
302
|
|
|
289
303
|
### Dependencies named after Node.js builtins
|
|
290
304
|
|
|
@@ -292,7 +306,7 @@ Some packages have the same name as a Node.js builtin (for instance `buffer` or
|
|
|
292
306
|
`process`).
|
|
293
307
|
|
|
294
308
|
**Solution**: if Knip reports such a dependency as unused, add it to
|
|
295
|
-
[ignoreDependencies][
|
|
309
|
+
[ignoreDependencies][24].
|
|
296
310
|
|
|
297
311
|
### Conditional or dynamic dependencies
|
|
298
312
|
|
|
@@ -322,7 +336,7 @@ reported as unused.
|
|
|
322
336
|
This limitation exists because Knip executes configuration files to parse their
|
|
323
337
|
exported value. While Knip can parse configuration files statically using AST
|
|
324
338
|
(Abstract Syntax Tree) analysis, this approach becomes complex very quickly and
|
|
325
|
-
most of the time it is easier to use the [`ignoreDependencies`][
|
|
339
|
+
most of the time it is easier to use the [`ignoreDependencies`][24]
|
|
326
340
|
configuration option for conditionals.
|
|
327
341
|
|
|
328
342
|
```json title="knip.json"
|
|
@@ -360,7 +374,7 @@ In strict production mode, even when re-exported and part of the package's
|
|
|
360
374
|
public API, Knip does not try to figure out what exactly are "production types"
|
|
361
375
|
and expects those in `devDependencies`.
|
|
362
376
|
|
|
363
|
-
**Solution**: list exceptions in [ignoreDependencies][
|
|
377
|
+
**Solution**: list exceptions in [ignoreDependencies][24].
|
|
364
378
|
|
|
365
379
|
### Unlisted dependencies
|
|
366
380
|
|
|
@@ -392,7 +406,7 @@ reported as an unlisted binary as there is no package that contains it.
|
|
|
392
406
|
|
|
393
407
|
Binaries that are installed on the OS already and thus likely not meant to be
|
|
394
408
|
installed from npm are not reported as unlisted (details: [list of ignored
|
|
395
|
-
binaries in source][
|
|
409
|
+
binaries in source][34]).
|
|
396
410
|
|
|
397
411
|
#### Missing binaries
|
|
398
412
|
|
|
@@ -402,7 +416,7 @@ either the way your package manager installs dependencies and binaries, or by
|
|
|
402
416
|
not running Knip from the root of the repository.
|
|
403
417
|
|
|
404
418
|
**Solution**: run Knip from the project root. If needed, [lint workspaces
|
|
405
|
-
individually][
|
|
419
|
+
individually][35].
|
|
406
420
|
|
|
407
421
|
Sometimes binaries and how they're reported can be a bit confusing. See this
|
|
408
422
|
example:
|
|
@@ -438,10 +452,10 @@ or consider the binary and package(s) referenced, respectively.
|
|
|
438
452
|
Knip may ignore or be unable to resolve an import specifier or dependency
|
|
439
453
|
references. The most common causes for unresolved imports:
|
|
440
454
|
|
|
441
|
-
- [Template strings][
|
|
442
|
-
- [Extensionless imports][
|
|
443
|
-
- [Unrecognized path aliases][
|
|
444
|
-
- [External aliased imports][
|
|
455
|
+
- [Template strings][36]
|
|
456
|
+
- [Extensionless imports][30]
|
|
457
|
+
- [Unrecognized path aliases][37]
|
|
458
|
+
- [External aliased imports][38]
|
|
445
459
|
|
|
446
460
|
### Template strings
|
|
447
461
|
|
|
@@ -478,19 +492,19 @@ browsers) require a file extension for import specifiers.
|
|
|
478
492
|
|
|
479
493
|
### Unrecognized path aliases
|
|
480
494
|
|
|
481
|
-
Knip considers TS config path aliases and [paths configured in knip.json][
|
|
495
|
+
Knip considers TS config path aliases and [paths configured in knip.json][39],
|
|
482
496
|
but not those in e.g. Webpack or Vite configurations.
|
|
483
497
|
|
|
484
|
-
**Solution**: configure [paths][
|
|
485
|
-
[`ignoreUnresolved`][
|
|
498
|
+
**Solution**: configure [paths][39] or try relative imports. Otherwise, use
|
|
499
|
+
[`ignoreUnresolved`][40] as a last resort.
|
|
486
500
|
|
|
487
501
|
### External aliased imports
|
|
488
502
|
|
|
489
503
|
External libraries may use aliased imports that aren't resolved by Knip.
|
|
490
504
|
|
|
491
|
-
For instance, [unplugin-icons][
|
|
505
|
+
For instance, [unplugin-icons][41] does this to import icons from icon sets as
|
|
492
506
|
components. Such imports are reported as unused. Use the [`paths` configuration
|
|
493
|
-
option][
|
|
507
|
+
option][39] to tell Knip where to find the icon types:
|
|
494
508
|
|
|
495
509
|
```json title="knip.json"
|
|
496
510
|
{
|
|
@@ -501,9 +515,9 @@ option][37] to tell Knip where to find the icon types:
|
|
|
501
515
|
```
|
|
502
516
|
|
|
503
517
|
Where `[framework]` is the name of the framework you're using (see [available
|
|
504
|
-
types][
|
|
518
|
+
types][42]).
|
|
505
519
|
|
|
506
|
-
**Solution**: try [--include-libs][
|
|
520
|
+
**Solution**: try [--include-libs][43] or configure [paths][39].
|
|
507
521
|
|
|
508
522
|
## Unused exports
|
|
509
523
|
|
|
@@ -511,17 +525,17 @@ By default, Knip does not report unused exports of `entry` files.
|
|
|
511
525
|
|
|
512
526
|
The most common causes for unused exports include:
|
|
513
527
|
|
|
514
|
-
- [Namespace enumerations][
|
|
515
|
-
- [External libraries][
|
|
528
|
+
- [Namespace enumerations][44]
|
|
529
|
+
- [External libraries][45]
|
|
516
530
|
|
|
517
|
-
Use the `--exports` flag to [filter][
|
|
531
|
+
Use the `--exports` flag to [filter][17] and focus only on issues related to
|
|
518
532
|
exports:
|
|
519
533
|
|
|
520
534
|
```sh
|
|
521
535
|
knip --exports
|
|
522
536
|
```
|
|
523
537
|
|
|
524
|
-
Use [includeEntryExports][
|
|
538
|
+
Use [includeEntryExports][46] to report unused exports of entry files as well.
|
|
525
539
|
This can be set per workspace.
|
|
526
540
|
|
|
527
541
|
### Namespace enumerations
|
|
@@ -533,7 +547,7 @@ are then **not** reported.
|
|
|
533
547
|
**Solution**: if all exports on imported namespaces should be considered
|
|
534
548
|
individually, include the `nsExports` issue type to disable the heuristic.
|
|
535
549
|
|
|
536
|
-
See [namespace imports][
|
|
550
|
+
See [namespace imports][47] to see all related patterns.
|
|
537
551
|
|
|
538
552
|
### External libraries
|
|
539
553
|
|
|
@@ -569,22 +583,22 @@ Knip does not include external type definitions by default so it won't see the
|
|
|
569
583
|
export being referenced.
|
|
570
584
|
|
|
571
585
|
**Solution**: include the type definitions of external libraries with the
|
|
572
|
-
[--include-libs][
|
|
586
|
+
[--include-libs][43] flag:
|
|
573
587
|
|
|
574
588
|
```shell
|
|
575
589
|
knip --include-libs
|
|
576
590
|
```
|
|
577
591
|
|
|
578
592
|
This comes at a performance and memory penalty, but should give better results
|
|
579
|
-
if you need it. This flag is implied when [classMembers][
|
|
593
|
+
if you need it. This flag is implied when [classMembers][48] are included (that
|
|
580
594
|
feature comes with roughly the same performance penalty).
|
|
581
595
|
|
|
582
596
|
### Exclude exports from the report
|
|
583
597
|
|
|
584
598
|
To exclude false positives from the report, there are a few options:
|
|
585
599
|
|
|
586
|
-
- [Ignore exports used in file][
|
|
587
|
-
- Individual exports can be [tagged using JSDoc syntax][
|
|
600
|
+
- [Ignore exports used in file][49] for exports used internally.
|
|
601
|
+
- Individual exports can be [tagged using JSDoc syntax][50].
|
|
588
602
|
- Have the export in an entry file:
|
|
589
603
|
|
|
590
604
|
- Add the file to the `entry` file patterns array in the configuration.
|
|
@@ -595,11 +609,11 @@ To exclude false positives from the report, there are a few options:
|
|
|
595
609
|
### Missing unused exports?
|
|
596
610
|
|
|
597
611
|
Did you expect certain exports in the report, but are they missing? They might
|
|
598
|
-
be exported from an entry file. In that case, use [--include-entry-exports][
|
|
612
|
+
be exported from an entry file. In that case, use [--include-entry-exports][46]
|
|
599
613
|
to make Knip also report unused exports in entry files.
|
|
600
614
|
|
|
601
615
|
The exports of non-standard extensions like `.astro`, `.mdx`, `.vue` or
|
|
602
|
-
`.svelte` are not available by default. See [compilers][
|
|
616
|
+
`.svelte` are not available by default. See [compilers][21] for more details on
|
|
603
617
|
how to include them.
|
|
604
618
|
|
|
605
619
|
### Class members
|
|
@@ -614,10 +628,10 @@ knip --include classMembers
|
|
|
614
628
|
This option is also available in the Knip configuration file. Note that this
|
|
615
629
|
feature comes at a cost: linting will take more time and more memory.
|
|
616
630
|
|
|
617
|
-
Individual class members can be [tagged using JSDoc syntax][
|
|
631
|
+
Individual class members can be [tagged using JSDoc syntax][50].
|
|
618
632
|
|
|
619
633
|
Classes exported from entry files are ignored, and so are their members. Use
|
|
620
|
-
[--include-entry-exports][
|
|
634
|
+
[--include-entry-exports][46] to make Knip also report members of unused exports
|
|
621
635
|
in entry files.
|
|
622
636
|
|
|
623
637
|
### Enum members
|
|
@@ -629,64 +643,66 @@ Reporting such members can be disabled:
|
|
|
629
643
|
knip --exclude enumMembers
|
|
630
644
|
```
|
|
631
645
|
|
|
632
|
-
Individual enum members can be [tagged using JSDoc syntax][
|
|
646
|
+
Individual enum members can be [tagged using JSDoc syntax][50].
|
|
633
647
|
|
|
634
648
|
Enums exported from entry files are ignored, and so are their members. Use
|
|
635
|
-
[--include-entry-exports][
|
|
649
|
+
[--include-entry-exports][46] to make Knip also report members of unused exports
|
|
636
650
|
in entry files.
|
|
637
651
|
|
|
638
652
|
## Feedback or false positives?
|
|
639
653
|
|
|
640
654
|
If you believe Knip incorrectly reports something as unused (i.e. there's a
|
|
641
|
-
false positive), feel free to create a [minimal reproduction][
|
|
655
|
+
false positive), feel free to create a [minimal reproduction][51] and open an
|
|
642
656
|
issue on GitHub. It'll make Knip better for everyone!
|
|
643
657
|
|
|
644
658
|
[1]: #unused-files
|
|
645
659
|
[2]: #unused-dependencies
|
|
646
660
|
[3]: #unresolved-imports
|
|
647
661
|
[4]: #unused-exports
|
|
648
|
-
[5]:
|
|
649
|
-
[6]:
|
|
650
|
-
[7]: #
|
|
651
|
-
[8]: #
|
|
652
|
-
[9]: #
|
|
653
|
-
[10]: #
|
|
654
|
-
[11]: #
|
|
655
|
-
[12]: #
|
|
656
|
-
[13]: #
|
|
657
|
-
[14]: #
|
|
658
|
-
[15]:
|
|
659
|
-
[16]:
|
|
660
|
-
[17]: ../features/
|
|
661
|
-
[18]:
|
|
662
|
-
[19]: ../features/
|
|
663
|
-
[20]: ../
|
|
664
|
-
[21]: ../
|
|
665
|
-
[22]: ../
|
|
666
|
-
[23]: ../
|
|
667
|
-
[24]: ../
|
|
668
|
-
[25]: ../
|
|
669
|
-
[26]: ../
|
|
670
|
-
[27]: #
|
|
671
|
-
[28]:
|
|
672
|
-
[29]: #
|
|
673
|
-
[30]: #
|
|
674
|
-
[31]: #
|
|
675
|
-
[32]:
|
|
676
|
-
[33]:
|
|
677
|
-
[34]: #
|
|
678
|
-
[35]: #
|
|
679
|
-
[36]: #
|
|
680
|
-
[37]:
|
|
681
|
-
[38]:
|
|
682
|
-
[39]:
|
|
683
|
-
[40]:
|
|
684
|
-
[41]:
|
|
685
|
-
[42]:
|
|
686
|
-
[43]:
|
|
687
|
-
[44]:
|
|
688
|
-
[45]:
|
|
689
|
-
[46]: #
|
|
690
|
-
[47]: ../
|
|
691
|
-
[48]:
|
|
692
|
-
[49]: ../
|
|
662
|
+
[5]: ../reference/integrations.md
|
|
663
|
+
[6]: ../reference/configuration-hints.md
|
|
664
|
+
[7]: #missing-generated-files
|
|
665
|
+
[8]: #dynamic-import-specifiers
|
|
666
|
+
[9]: #unsupported-arguments-in-scripts
|
|
667
|
+
[10]: #unsupported-file-formats
|
|
668
|
+
[11]: #missing-plugin
|
|
669
|
+
[12]: #incomplete-plugin
|
|
670
|
+
[13]: #typescript-path-aliases-in-monorepos
|
|
671
|
+
[14]: #relative-paths-across-workspaces
|
|
672
|
+
[15]: #integrated-monorepos
|
|
673
|
+
[16]: #auto-mocking-or-auto-imports
|
|
674
|
+
[17]: ../features/rules-and-filters.md#filters
|
|
675
|
+
[18]: ./configuring-project-files.md
|
|
676
|
+
[19]: ../features/source-mapping.md
|
|
677
|
+
[20]: ../features/script-parser.md
|
|
678
|
+
[21]: ../features/compilers.md
|
|
679
|
+
[22]: ../writing-a-plugin/index.md
|
|
680
|
+
[23]: ../reference/plugins.md
|
|
681
|
+
[24]: ../reference/configuration.md#ignoredependencies
|
|
682
|
+
[25]: ../explanations/plugins.md#entry-files
|
|
683
|
+
[26]: ../explanations/entry-files.md#plugins
|
|
684
|
+
[27]: ../reference/faq.md#why-cant-i-use-path-aliases-to-reference-other-workspaces
|
|
685
|
+
[28]: ../features/integrated-monorepos.md
|
|
686
|
+
[29]: #missing-or-incomplete-plugin
|
|
687
|
+
[30]: #unrecognized-reference
|
|
688
|
+
[31]: #type-definition-packages
|
|
689
|
+
[32]: #dependencies-named-after-nodejs-builtins
|
|
690
|
+
[33]: #unlisted-binaries
|
|
691
|
+
[34]: https://github.com/webpro-nl/knip/blob/e031018e676c47d84873cc2403251c0111ef318d/packages/knip/src/constants.ts#L39-L148
|
|
692
|
+
[35]: ../features/monorepos-and-workspaces.md#lint-a-single-workspace
|
|
693
|
+
[36]: #template-strings
|
|
694
|
+
[37]: #unrecognized-path-aliases
|
|
695
|
+
[38]: #external-aliased-imports
|
|
696
|
+
[39]: ../reference/configuration.md#paths
|
|
697
|
+
[40]: ../reference/configuration.md#ignoreunresolved
|
|
698
|
+
[41]: https://www.npmjs.com/package/unplugin-icons
|
|
699
|
+
[42]: https://github.com/unplugin/unplugin-icons/tree/main/types
|
|
700
|
+
[43]: ../reference/cli.md#--include-libs
|
|
701
|
+
[44]: #namespace-enumerations
|
|
702
|
+
[45]: #external-libraries
|
|
703
|
+
[46]: ../reference/configuration.md#includeentryexports
|
|
704
|
+
[47]: ../guides/namespace-imports.md
|
|
705
|
+
[48]: #class-members
|
|
706
|
+
[49]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
707
|
+
[50]: ../reference/jsdoc-tsdoc-tags.md
|
|
708
|
+
[51]: ../guides/issue-reproduction.md
|
|
@@ -19,6 +19,8 @@ influence the issue at hand, such as:
|
|
|
19
19
|
- Dependent or depending workspaces in a monorepo
|
|
20
20
|
- Knip configuration in `knip.json`
|
|
21
21
|
|
|
22
|
+
## Keep it minimal
|
|
23
|
+
|
|
22
24
|
Create the minimum of source code and configuration with a few files to
|
|
23
25
|
reproduce and demonstrate the issue. Having this as a basis has many benefits:
|
|
24
26
|
|
|
@@ -30,6 +32,12 @@ reproduce and demonstrate the issue. Having this as a basis has many benefits:
|
|
|
30
32
|
Providing this with an issue description will help us help you and improve the
|
|
31
33
|
chances the issue can be looked into efficiently and in a timely manner.
|
|
32
34
|
|
|
35
|
+
Useful **complements** to a minimal reproduction might include:
|
|
36
|
+
|
|
37
|
+
- Screenshots, videos, code snippets or log output
|
|
38
|
+
- Links to an existing project repository
|
|
39
|
+
- Applications scaffolded by tools like Angular or Svelte CLI
|
|
40
|
+
|
|
33
41
|
## Before opening an issue
|
|
34
42
|
|
|
35
43
|
Before opening an issue, please make sure you:
|
|
@@ -67,13 +75,9 @@ including:
|
|
|
67
75
|
- A public repository on e.g. GitHub or GitLab.
|
|
68
76
|
- A new [fixtures folder in the Knip repository][9].
|
|
69
77
|
|
|
70
|
-
The goal is to have an easy and common understanding and reproduction.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
the full picture and aren't complete nor actionable.
|
|
74
|
-
|
|
75
|
-
If you're unable to create a reproduction using one of the methods described
|
|
76
|
-
then please clearly explain this in the issue or [contact me][10].
|
|
78
|
+
The goal is to have an easy and common understanding and reproduction. If you're
|
|
79
|
+
unable to create a reproduction using one of the methods described then please
|
|
80
|
+
clearly explain this in the issue or [contact me][10].
|
|
77
81
|
|
|
78
82
|
## Pull Request
|
|
79
83
|
|