@knip/mcp 0.0.19 → 0.0.21
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 +16 -16
- package/src/docs/blog/knip-v3.mdx +1 -1
- package/src/docs/blog/knip-v4.mdx +1 -1
- package/src/docs/docs/blog/knip-v3.mdx +1 -1
- package/src/docs/docs/blog/knip-v4.mdx +1 -1
- package/src/docs/docs/explanations/plugins.md +2 -2
- package/src/docs/docs/guides/handling-issues.mdx +1 -1
- package/src/docs/docs/guides/performance.md +1 -1
- package/src/docs/docs/overview/features.md +1 -1
- package/src/docs/docs/reference/faq.md +101 -38
- package/src/docs/docs/reference/issue-types.md +23 -21
- package/src/docs/docs/reference/jsdoc-tsdoc-tags.md +12 -1
- package/src/docs/docs/reference/plugins.md +7 -1
- package/src/docs/docs/writing-a-plugin/index.md +1 -1
- package/src/docs/explanations/comparison-and-migration.md +2 -0
- package/src/docs/explanations/plugins.md +22 -4
- package/src/docs/features/auto-fix.mdx +2 -2
- package/src/docs/guides/handling-issues.mdx +1 -1
- package/src/docs/guides/issue-reproduction.md +7 -6
- package/src/docs/guides/performance.md +1 -1
- package/src/docs/overview/features.md +1 -1
- package/src/docs/reference/faq.md +101 -38
- package/src/docs/reference/jsdoc-tsdoc-tags.md +12 -1
- package/src/docs/reference/plugins.md +7 -1
- package/src/docs/writing-a-plugin/index.md +1 -1
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knip/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Knip MCP Server",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"knip-mcp": "./src/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"exports": {
|
|
10
|
-
".": "./src/server.js",
|
|
11
|
-
"./tools": "./src/tools.js"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"src"
|
|
15
|
-
],
|
|
16
5
|
"keywords": [
|
|
17
6
|
"knip",
|
|
18
7
|
"mcp",
|
|
19
8
|
"model-context-protocol"
|
|
20
9
|
],
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"author": "Lars Kappert <lars@webpro.nl>",
|
|
21
12
|
"repository": {
|
|
22
13
|
"type": "git",
|
|
23
14
|
"url": "git+https://github.com/webpro-nl/knip.git",
|
|
24
15
|
"directory": "packages/mcp-server"
|
|
25
16
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
17
|
+
"bin": {
|
|
18
|
+
"knip-mcp": "./src/cli.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/server.js",
|
|
26
|
+
"./tools": "./src/tools.js"
|
|
27
|
+
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
30
30
|
"zod": "^4.1.11",
|
|
31
|
-
"knip": "^5.
|
|
31
|
+
"knip": "^5.87.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.18.0"
|
|
@@ -82,7 +82,7 @@ Remember, Knip it before you ship it! Have a great day ☀️
|
|
|
82
82
|
[3]: https://github.com/webpro-nl/knip/stargazers
|
|
83
83
|
[4]: https://github.com/webpro-nl/knip/network/dependents
|
|
84
84
|
[5]: https://github.com/marketplace/actions/knip-reporter
|
|
85
|
-
[6]: ../reference/cli.md
|
|
85
|
+
[6]: ../reference/cli.md#--no-exit-code
|
|
86
86
|
[7]: ../features/production-mode.md
|
|
87
87
|
[8]: ../reference/jsdoc-tsdoc-tags.md#internal
|
|
88
88
|
[9]: ../features/reporters.md#json
|
|
@@ -82,7 +82,7 @@ Remember, Knip it before you ship it! Have a great day ☀️
|
|
|
82
82
|
[3]: https://github.com/webpro-nl/knip/stargazers
|
|
83
83
|
[4]: https://github.com/webpro-nl/knip/network/dependents
|
|
84
84
|
[5]: https://github.com/marketplace/actions/knip-reporter
|
|
85
|
-
[6]: ../reference/cli.md
|
|
85
|
+
[6]: ../reference/cli.md#--no-exit-code
|
|
86
86
|
[7]: ../features/production-mode.md
|
|
87
87
|
[8]: ../reference/jsdoc-tsdoc-tags.md#internal
|
|
88
88
|
[9]: ../features/reporters.md#json
|
|
@@ -100,8 +100,8 @@ dependencies.
|
|
|
100
100
|
For example, if `next` is listed as a dependency in `package.json`, the Next.js
|
|
101
101
|
plugin will automatically add multiple patterns as entry files, such as
|
|
102
102
|
`pages/**/*.{js,jsx,ts,tsx}`. If `vitest` is listed, the Vitest plugin adds
|
|
103
|
-
`**/*.{test,test-d,spec}.ts` as entry file patterns. Most plugins have
|
|
104
|
-
files configured, so you don't have to.
|
|
103
|
+
`**/*.{test,test-d,spec,spec-d}.ts` as entry file patterns. Most plugins have
|
|
104
|
+
entry files configured, so you don't have to.
|
|
105
105
|
|
|
106
106
|
It's mostly plugins for meta frameworks and test runners that have `entry` files
|
|
107
107
|
configured.
|
|
@@ -689,7 +689,7 @@ issue on GitHub. It'll make Knip better for everyone!
|
|
|
689
689
|
[32]: #dependencies-named-after-nodejs-builtins
|
|
690
690
|
[33]: #unlisted-binaries
|
|
691
691
|
[34]: https://github.com/webpro-nl/knip/blob/e031018e676c47d84873cc2403251c0111ef318d/packages/knip/src/constants.ts#L39-L148
|
|
692
|
-
[35]: ../features/monorepos-and-workspaces.md#
|
|
692
|
+
[35]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
693
693
|
[36]: #template-strings
|
|
694
694
|
[37]: #unrecognized-path-aliases
|
|
695
695
|
[38]: #external-aliased-imports
|
|
@@ -105,4 +105,4 @@ individual workspaces][6].
|
|
|
105
105
|
[3]: ../guides/handling-issues.mdx#external-libraries
|
|
106
106
|
[4]: ../reference/cli.md#--performance
|
|
107
107
|
[5]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
108
|
-
[6]: ../features/monorepos-and-workspaces.md#
|
|
108
|
+
[6]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
@@ -63,4 +63,4 @@ Also see [related tooling][2].
|
|
|
63
63
|
[23]: ../features/production-mode.md#strict-mode
|
|
64
64
|
[24]: ../guides/troubleshooting.md#trace
|
|
65
65
|
[25]: ../reference/cli.md#--watch
|
|
66
|
-
[26]: ../features/monorepos-and-workspaces.md#
|
|
66
|
+
[26]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
@@ -22,6 +22,65 @@ This FAQ is an attempt to provide some perspective on a few design decisions and
|
|
|
22
22
|
why certain things work the way they do. Here and there it's intentionally a bit
|
|
23
23
|
more in-depth than the rest of the docs.
|
|
24
24
|
|
|
25
|
+
## Why should I even bother to do all this?
|
|
26
|
+
|
|
27
|
+
Because the payoff is huge. While it might take a bit of effort to configure
|
|
28
|
+
Knip correctly initially, a clean module graph gives you absolute confidence in
|
|
29
|
+
your codebase. You can delete dead code, remove unused dependencies, and
|
|
30
|
+
refactor with certainty. It prevents the slow accumulation of technical debt and
|
|
31
|
+
keeps your project lean and fast. Once configured, Knip runs quickly in CI and
|
|
32
|
+
keeps your codebase pristine automatically.
|
|
33
|
+
|
|
34
|
+
:::tip
|
|
35
|
+
|
|
36
|
+
Try the [Knip MCP Server][1] or the [Knip Editor Extension][2]. Let your coding
|
|
37
|
+
agent use the built-in MCP Server and create a custom `knip.json` for you, so
|
|
38
|
+
you don't have to.
|
|
39
|
+
|
|
40
|
+
:::
|
|
41
|
+
|
|
42
|
+
## Common Pitfalls
|
|
43
|
+
|
|
44
|
+
### Why shouldn't I ignore or disable configuration hints?
|
|
45
|
+
|
|
46
|
+
Configuration hints are critical for building a healthy and accurate module
|
|
47
|
+
graph. They usually indicate that Knip cannot resolve a dependency, plugin, or
|
|
48
|
+
entry file. If you ignore or disable these hints, Knip's understanding of your
|
|
49
|
+
project will be incomplete, which inevitably leads to false positives (reporting
|
|
50
|
+
used code as unused). Always address configuration hints first before looking at
|
|
51
|
+
other reported issues.
|
|
52
|
+
|
|
53
|
+
### Why is it a bad idea to use `ignore` patterns like I do in ESLint?
|
|
54
|
+
|
|
55
|
+
Knip is not a regular file-based linter like ESLint. It works by analyzing the
|
|
56
|
+
entire interconnected module graph of your project. Using `ignore` patterns does
|
|
57
|
+
not exclude files from the analysis, it only suppresses the reporting of issues
|
|
58
|
+
in those files. This hides real issues and creates blind spots. Instead of
|
|
59
|
+
ignoring files, ensure your entry points and plugins are configured correctly,
|
|
60
|
+
and use `project` patterns to define the boundaries of your codebase. Read more:
|
|
61
|
+
[Configuring Project Files][3].
|
|
62
|
+
|
|
63
|
+
If you have specific exports (such as types) that are only used within the file
|
|
64
|
+
they are defined, use the [ignoreExportsUsedInFile][4] configuration option
|
|
65
|
+
rather than ignoring the file entirely.
|
|
66
|
+
|
|
67
|
+
### How should I exclude tests and development tools from the analysis?
|
|
68
|
+
|
|
69
|
+
A common mistake is trying to exclude test files, storybooks, or development
|
|
70
|
+
tools using `project` or `ignore` patterns. The correct approach is to use
|
|
71
|
+
[production mode][5]. This mode is specifically designed to strictly analyze
|
|
72
|
+
only your production source code and `dependencies`, automatically excluding
|
|
73
|
+
tests and `devDependencies` without requiring complex ignore rules.
|
|
74
|
+
|
|
75
|
+
### Why shouldn't I run `knip --fix` immediately?
|
|
76
|
+
|
|
77
|
+
Running `knip --fix` before your configuration is fully settled is dangerous. If
|
|
78
|
+
your configuration is missing entry points or has unresolved hints, Knip might
|
|
79
|
+
think perfectly valid, actively used code is unused. Auto-fixing in this state
|
|
80
|
+
can lead to deleting code that your application relies on. Always verify the
|
|
81
|
+
reported issues manually and ensure your configuration is solid before using the
|
|
82
|
+
`--fix` flag.
|
|
83
|
+
|
|
25
84
|
## Comparison
|
|
26
85
|
|
|
27
86
|
### Why isn't Knip an ESLint plugin?
|
|
@@ -53,10 +112,10 @@ Issues reported by the linter are for you to handle and review.
|
|
|
53
112
|
|
|
54
113
|
Besides those differences, Knip has a broader scope:
|
|
55
114
|
|
|
56
|
-
- Improve DX (see [less is more][
|
|
57
|
-
- Unless using [production mode][
|
|
115
|
+
- Improve DX (see [less is more][6]).
|
|
116
|
+
- Unless using [production mode][5], also lint all source code like tests,
|
|
58
117
|
scripts and Storybook stories.
|
|
59
|
-
- Handle more [types of issues][
|
|
118
|
+
- Handle more [types of issues][7] (such as unlisted dependencies).
|
|
60
119
|
|
|
61
120
|
## Synergy
|
|
62
121
|
|
|
@@ -89,13 +148,13 @@ Building up the module and dependency graphs requires non-standard module
|
|
|
89
148
|
resolution and not only static but also dynamic analysis (i.e. actually load and
|
|
90
149
|
execute modules), such as for parsers of plugins to receive the exported value
|
|
91
150
|
of dynamic tooling configuration files. Additionally, [exports consumed by
|
|
92
|
-
external libraries][
|
|
151
|
+
external libraries][8] require type information, as supported by the TypeScript
|
|
93
152
|
backend. Last but not least, shell script parsing is required to find the right
|
|
94
153
|
entry files, configuration files and dependencies accurately.
|
|
95
154
|
|
|
96
155
|
The rippling effect of plugins and recursively adding entry files and
|
|
97
156
|
dependencies to build up the graphs is also exactly what's meant by
|
|
98
|
-
["comprehensive" here][
|
|
157
|
+
["comprehensive" here][9].
|
|
99
158
|
|
|
100
159
|
## Building the graphs
|
|
101
160
|
|
|
@@ -143,7 +202,7 @@ files (`config/vitest.config.ts` and `playwright.e2e.config.ts` in the examples
|
|
|
143
202
|
above). They're recognized as configuration files and passed to their respective
|
|
144
203
|
plugins, and may contain additional entry files.
|
|
145
204
|
|
|
146
|
-
Entry files are added to the module graph. [Module resolution][
|
|
205
|
+
Entry files are added to the module graph. [Module resolution][10] might result
|
|
147
206
|
in additional entry files recursively until no more entry files are found.
|
|
148
207
|
|
|
149
208
|
### What does Knip look for in source files?
|
|
@@ -156,7 +215,7 @@ all nodes of the generated AST to find:
|
|
|
156
215
|
- Accessed properties on namespace imports and re-exports to track individual
|
|
157
216
|
export usage
|
|
158
217
|
- Calls to `require.resolve` and `import.meta.resolve`
|
|
159
|
-
- Scripts in template strings (passed to [script parser][
|
|
218
|
+
- Scripts in template strings (passed to [script parser][11])
|
|
160
219
|
|
|
161
220
|
### What's in the graphs?
|
|
162
221
|
|
|
@@ -194,7 +253,7 @@ there are a few issues with this approach:
|
|
|
194
253
|
|
|
195
254
|
- It requires lockfile parsing for each lockfile format and version of each
|
|
196
255
|
package manager.
|
|
197
|
-
- The lockfile doesn't contain whether the package [has types included][
|
|
256
|
+
- The lockfile doesn't contain whether the package [has types included][12].
|
|
198
257
|
|
|
199
258
|
## Module Resolution
|
|
200
259
|
|
|
@@ -215,12 +274,12 @@ seem to meet all requirements to be usable on its own by Knip:
|
|
|
215
274
|
`module.js`
|
|
216
275
|
|
|
217
276
|
A few strategies have been tried and tweaked, and Knip currently uses a
|
|
218
|
-
combination of [oxc-resolver][
|
|
277
|
+
combination of [oxc-resolver][13], the TypeScript module resolver and a few
|
|
219
278
|
customizations. This single custom module resolver function is hooked into the
|
|
220
279
|
TypeScript compiler and language service hosts.
|
|
221
280
|
|
|
222
|
-
Everything else is handled by `oxc-resolver` for things like [script
|
|
223
|
-
and resolving references to files in other workspaces.
|
|
281
|
+
Everything else is handled by `oxc-resolver` for things like [script
|
|
282
|
+
parsing][11] and resolving references to files in other workspaces.
|
|
224
283
|
|
|
225
284
|
### How does Knip handle non-standard import syntax?
|
|
226
285
|
|
|
@@ -250,7 +309,7 @@ file. They're not a concept in Knip.
|
|
|
250
309
|
|
|
251
310
|
A TypeScript program has a 1-to-1 relationship with workspaces if they're
|
|
252
311
|
analyzed in isolation. However, by default Knip optimizes for performance and
|
|
253
|
-
utilizes [workspace sharing][
|
|
312
|
+
utilizes [workspace sharing][14]. That's why debug output contains messages like
|
|
254
313
|
"Installed 2 programs for 29 workspaces".
|
|
255
314
|
|
|
256
315
|
### Why doesn't Knip match my TypeScript project structure?
|
|
@@ -282,7 +341,7 @@ Knip shares the files of multiple workspaces in a single program if their
|
|
|
282
341
|
configuration allows it. This optimization is enabled by default, while it also
|
|
283
342
|
allows the module resolver (one per program) to do some more caching.
|
|
284
343
|
|
|
285
|
-
Also see [workspace sharing][
|
|
344
|
+
Also see [workspace sharing][14].
|
|
286
345
|
|
|
287
346
|
### Why doesn't Knip just use `ts.findReferences`?
|
|
288
347
|
|
|
@@ -298,7 +357,7 @@ comprehensive graph include:
|
|
|
298
357
|
Without sacrificing these benefits, Knip does use `ts.findReferences` to find
|
|
299
358
|
references to class members (i.e. when the issue type `classMembers` is
|
|
300
359
|
included). In case analysis of exports requires type information of external
|
|
301
|
-
dependencies, the [`--include-libs ` flag][
|
|
360
|
+
dependencies, the [`--include-libs ` flag][8] will trigger the same.
|
|
302
361
|
|
|
303
362
|
### Why can't I use path aliases to reference other workspaces?
|
|
304
363
|
|
|
@@ -310,19 +369,19 @@ The recommendation and best practice is to list such workspaces/dependencies in
|
|
|
310
369
|
`package.json`, and import them as such. Other tooling should not have any
|
|
311
370
|
issues with this standard approach either.
|
|
312
371
|
|
|
313
|
-
Also see the example in [TypeScript path aliases in monorepos][
|
|
372
|
+
Also see the example in [TypeScript path aliases in monorepos][15].
|
|
314
373
|
|
|
315
374
|
### What's up with that configurable `tsconfig.json` location?
|
|
316
375
|
|
|
317
376
|
There's a difference between `--tsConfig [file]` as a CLI argument and the
|
|
318
377
|
`typescript.config` option in Knip configuration.
|
|
319
378
|
|
|
320
|
-
The [`--tsConfig [file]` option][
|
|
379
|
+
The [`--tsConfig [file]` option][16] is used to provide an alternative location
|
|
321
380
|
for the default root `tsconfig.json` file. Relevant `compilerOptions` include
|
|
322
381
|
`paths` and `moduleResolution`. This setting is only available at the root
|
|
323
382
|
level.
|
|
324
383
|
|
|
325
|
-
On the other hand, the [`config` option of the plugin][
|
|
384
|
+
On the other hand, the [`config` option of the plugin][17] can be set per
|
|
326
385
|
workspace. The TypeScript plugin extracts referenced external dependencies such
|
|
327
386
|
as those in `extends`, `compilerOptions.types` and JSX settings:
|
|
328
387
|
|
|
@@ -346,7 +405,7 @@ From this example, Knip can determine whether the `@tsconfig/node20` and
|
|
|
346
405
|
for `tsconfig.json` can be set per workspace.
|
|
347
406
|
- In case path aliases from `compilerOptions.paths` aren't picked up by Knip,
|
|
348
407
|
either use `--tsConfig [file]` to target a different `tsconfig.json`, or
|
|
349
|
-
manually add [paths][
|
|
408
|
+
manually add [paths][18] to the Knip configuration. The latter can be done per
|
|
350
409
|
workspace.
|
|
351
410
|
|
|
352
411
|
## Compilers
|
|
@@ -369,7 +428,7 @@ other file types.
|
|
|
369
428
|
Knip comes with basic "compilers" for a few common non-standard file types.
|
|
370
429
|
They're not actual compilers, they're regular expressions only to extract import
|
|
371
430
|
statements. Override the built-in Vue "compiler" with the real one in your
|
|
372
|
-
project. Also see the answer to the previous question and [Compilers][
|
|
431
|
+
project. Also see the answer to the previous question and [Compilers][19].
|
|
373
432
|
|
|
374
433
|
## Miscellaneous
|
|
375
434
|
|
|
@@ -389,7 +448,7 @@ Which mode should've been the default? They both have their merits:
|
|
|
389
448
|
tooling, including most issues found in production mode. This mode has the
|
|
390
449
|
most impact on DX, for the same reason.
|
|
391
450
|
|
|
392
|
-
Also see [production mode][
|
|
451
|
+
Also see [production mode][5].
|
|
393
452
|
|
|
394
453
|
### Why doesn't Knip have...?
|
|
395
454
|
|
|
@@ -410,21 +469,25 @@ Examples of features that have been requested include:
|
|
|
410
469
|
|
|
411
470
|
These are all interesting ideas, but most increase the API surface area, and all
|
|
412
471
|
require more development efforts and maintenance. Time is limited and
|
|
413
|
-
[sponsorships][
|
|
414
|
-
|
|
415
|
-
[1]: ../
|
|
416
|
-
[2]: ../
|
|
417
|
-
[3]:
|
|
418
|
-
[4]: ../
|
|
419
|
-
[5]: ../
|
|
420
|
-
[6]: #
|
|
421
|
-
[7]:
|
|
422
|
-
[8]: ../guides/handling-issues.mdx#
|
|
423
|
-
[9]:
|
|
424
|
-
[10]:
|
|
425
|
-
[11]: ../
|
|
426
|
-
[12]: ../
|
|
427
|
-
[13]:
|
|
428
|
-
[14]: ../
|
|
429
|
-
[15]: ../
|
|
430
|
-
[16]: /
|
|
472
|
+
[sponsorships][20] currently don't cover - this can change though!
|
|
473
|
+
|
|
474
|
+
[1]: ../reference/integrations.md#mcp-server
|
|
475
|
+
[2]: ../reference/integrations.md#vs-code-extension
|
|
476
|
+
[3]: ../guides/configuring-project-files.md
|
|
477
|
+
[4]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
478
|
+
[5]: ../features/production-mode.md
|
|
479
|
+
[6]: ../explanations/why-use-knip.md#less-is-more
|
|
480
|
+
[7]: ./issue-types.md
|
|
481
|
+
[8]: ../guides/handling-issues.mdx#external-libraries
|
|
482
|
+
[9]: ../explanations/why-use-knip.md#comprehensive
|
|
483
|
+
[10]: #module-resolution
|
|
484
|
+
[11]: ../features/script-parser.md
|
|
485
|
+
[12]: ../guides/handling-issues.mdx#type-definition-packages
|
|
486
|
+
[13]: https://oxc.rs/docs/guide/usage/resolver.html
|
|
487
|
+
[14]: ../guides/performance.md#workspace-sharing
|
|
488
|
+
[15]: ../guides/handling-issues.mdx#typescript-path-aliases-in-monorepos
|
|
489
|
+
[16]: ../reference/cli.md#--tsconfig-file
|
|
490
|
+
[17]: ../explanations/plugins.md#configuration-files
|
|
491
|
+
[18]: ../reference/configuration.md#paths
|
|
492
|
+
[19]: ../features/compilers.md
|
|
493
|
+
[20]: /sponsors
|
|
@@ -5,23 +5,23 @@ tableOfContents: false
|
|
|
5
5
|
|
|
6
6
|
Knip reports the following types of issues:
|
|
7
7
|
|
|
8
|
-
| Title | Description
|
|
9
|
-
| :----------------------------------- |
|
|
10
|
-
| Unused files | Unable to find a reference to this file
|
|
11
|
-
| Unused dependencies | Unable to find a reference to this dependency
|
|
12
|
-
| Unused devDependencies | Unable to find a reference to this devDependency
|
|
13
|
-
| Referenced optional peerDependencies | Optional peer dependency is
|
|
14
|
-
| Unlisted dependencies | Used dependencies not listed in package.json
|
|
15
|
-
| Unlisted binaries | Binaries from dependencies not listed in package.json
|
|
16
|
-
| Unused catalog entries | Unable to find a reference to this catalog entry
|
|
17
|
-
| Unresolved imports | Unable to resolve this (import) specifier
|
|
18
|
-
| Unused exports | Unable to find a reference to this export
|
|
19
|
-
| Unused exported types | Unable to find a reference to this exported type
|
|
20
|
-
| Exports in used namespace | Namespace with export is
|
|
21
|
-
| Exported types in used namespace | Namespace with type is
|
|
22
|
-
| Unused exported enum members | Unable to find a reference to this enum member
|
|
23
|
-
| Unused exported class members | Unable to find a reference to this class member
|
|
24
|
-
| Duplicate exports | This is exported more than once
|
|
8
|
+
| Title | Description | | Key |
|
|
9
|
+
| :----------------------------------- | :---------------------------------------------------- | ----- | :------------------------- |
|
|
10
|
+
| Unused files | Unable to find a reference to this file | 🔧 | `files` |
|
|
11
|
+
| Unused dependencies | Unable to find a reference to this dependency | 🔧 | `dependencies` |
|
|
12
|
+
| Unused devDependencies | Unable to find a reference to this devDependency | 🔧 | `devDependencies` |
|
|
13
|
+
| Referenced optional peerDependencies | Optional peer dependency is used | | `optionalPeerDependencies` |
|
|
14
|
+
| Unlisted dependencies | Used dependencies not listed in package.json | | `unlisted` |
|
|
15
|
+
| Unlisted binaries | Binaries from dependencies not listed in package.json | | `binaries` |
|
|
16
|
+
| Unused catalog entries | Unable to find a reference to this catalog entry | 🔧 | `catalog` |
|
|
17
|
+
| Unresolved imports | Unable to resolve this (import) specifier | | `unresolved` |
|
|
18
|
+
| Unused exports | Unable to find a reference to this export | 🔧 | `exports` |
|
|
19
|
+
| Unused exported types | Unable to find a reference to this exported type | 🔧 | `types` |
|
|
20
|
+
| Exports in used namespace | Namespace with export is used, but not export itself | 🔧 🟠 | `nsExports` |
|
|
21
|
+
| Exported types in used namespace | Namespace with type is used, but not type itself | 🔧 🟠 | `nsTypes` |
|
|
22
|
+
| Unused exported enum members | Unable to find a reference to this enum member | 🔧 | `enumMembers` |
|
|
23
|
+
| Unused exported class members | Unable to find a reference to this class member | 🔧 🟠 | `classMembers` |
|
|
24
|
+
| Duplicate exports | This is exported more than once | | `duplicates` |
|
|
25
25
|
|
|
26
26
|
## Legend
|
|
27
27
|
|
|
@@ -33,11 +33,13 @@ Knip reports the following types of issues:
|
|
|
33
33
|
## Notes
|
|
34
34
|
|
|
35
35
|
- When an issue type has zero issues, it is not shown.
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
- Including or excluding `dependencies` (via CLI or configuration) automatically
|
|
37
|
+
includes or excludes `devDependencies` and `optionalPeerDependencies`. In
|
|
38
|
+
[rules][3], each key can be set individually.
|
|
39
|
+
- In [strict production mode][4], `devDependencies` are not included.
|
|
39
40
|
- The `types` issue type includes `enum`, `interface` and `type` exports.
|
|
40
41
|
|
|
41
42
|
[1]: ../features/auto-fix.mdx
|
|
42
43
|
[2]: ../features/rules-and-filters.md#filters
|
|
43
|
-
[3]: ../features/
|
|
44
|
+
[3]: ../features/rules-and-filters.md#rules
|
|
45
|
+
[4]: ../features/production-mode.md#strict-mode
|
|
@@ -30,7 +30,7 @@ Example:
|
|
|
30
30
|
export const myUnusedExport = 1;
|
|
31
31
|
|
|
32
32
|
/** @lintignore */
|
|
33
|
-
import Unresolved from
|
|
33
|
+
import Unresolved from "./generated/lib.js";
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
And then include (`+`) or exclude (`-`) these tagged exports from the report
|
|
@@ -42,6 +42,17 @@ knip --tags=-lintignore,-internal
|
|
|
42
42
|
|
|
43
43
|
Tags can also be [configured in `knip.json`][2].
|
|
44
44
|
|
|
45
|
+
When an excluded tag is no longer necessary because the export is actually used,
|
|
46
|
+
Knip reports a **tag hint**:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
Tag hints (1)
|
|
50
|
+
ignored unimported.ts Unused tag in unimported.ts: ignored → @custom
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This helps you clean up tags that were added to suppress issues that have since
|
|
54
|
+
been resolved.
|
|
55
|
+
|
|
45
56
|
## `@public`
|
|
46
57
|
|
|
47
58
|
By default, Knip reports unused exports in non-entry files.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Plugins (
|
|
2
|
+
title: Plugins (137)
|
|
3
3
|
tableOfContents: false
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -32,6 +32,7 @@ tableOfContents: false
|
|
|
32
32
|
- [Drizzle](/reference/plugins/drizzle "Drizzle")
|
|
33
33
|
- [Eleventy](/reference/plugins/eleventy "Eleventy")
|
|
34
34
|
- [ESLint](/reference/plugins/eslint "ESLint")
|
|
35
|
+
- [execa](/reference/plugins/execa "execa")
|
|
35
36
|
- [Expo](/reference/plugins/expo "Expo")
|
|
36
37
|
- [Expressive Code](/reference/plugins/expressive-code "Expressive Code")
|
|
37
38
|
- [Gatsby](/reference/plugins/gatsby "Gatsby")
|
|
@@ -75,16 +76,20 @@ tableOfContents: false
|
|
|
75
76
|
- [oclif](/reference/plugins/oclif "oclif")
|
|
76
77
|
- [Oxlint](/reference/plugins/oxlint "Oxlint")
|
|
77
78
|
- [Parcel](/reference/plugins/parcel "Parcel")
|
|
79
|
+
- [Payload CMS](/reference/plugins/payload "Payload CMS")
|
|
78
80
|
- [Playwright](/reference/plugins/playwright "Playwright")
|
|
79
81
|
- [Playwright for components](/reference/plugins/playwright-ct "Playwright for components")
|
|
80
82
|
- [playwright-test](/reference/plugins/playwright-test "playwright-test")
|
|
81
83
|
- [Plop](/reference/plugins/plop "Plop")
|
|
84
|
+
- [pm2](/reference/plugins/pm2 "pm2")
|
|
82
85
|
- [pnpm](/reference/plugins/pnpm "pnpm")
|
|
83
86
|
- [PostCSS](/reference/plugins/postcss "PostCSS")
|
|
84
87
|
- [Preconstruct](/reference/plugins/preconstruct "Preconstruct")
|
|
85
88
|
- [Prettier](/reference/plugins/prettier "Prettier")
|
|
86
89
|
- [Prisma](/reference/plugins/prisma "Prisma")
|
|
90
|
+
- [Qwik](/reference/plugins/qwik "Qwik")
|
|
87
91
|
- [React Cosmos](/reference/plugins/react-cosmos "React Cosmos")
|
|
92
|
+
- [React Native](/reference/plugins/react-native "React Native")
|
|
88
93
|
- [React Router](/reference/plugins/react-router "React Router")
|
|
89
94
|
- [Relay](/reference/plugins/relay "Relay")
|
|
90
95
|
- [Release It!](/reference/plugins/release-it "Release It!")
|
|
@@ -135,6 +140,7 @@ tableOfContents: false
|
|
|
135
140
|
- [xo](/reference/plugins/xo "xo")
|
|
136
141
|
- [Yarn](/reference/plugins/yarn "Yarn")
|
|
137
142
|
- [yorkie](/reference/plugins/yorkie "yorkie")
|
|
143
|
+
- [zx](/reference/plugins/zx "zx")
|
|
138
144
|
|
|
139
145
|
|
|
140
146
|
:::
|
|
@@ -365,7 +365,7 @@ The script adds the plugin to the JSON Schema and type definitions.
|
|
|
365
365
|
Run the test for your new plugin using one of the following commands:
|
|
366
366
|
|
|
367
367
|
```sh
|
|
368
|
-
|
|
368
|
+
node --test test/plugins/tool.test.ts
|
|
369
369
|
bun test test/plugins/tool.test.ts
|
|
370
370
|
```
|
|
371
371
|
|
|
@@ -86,8 +86,8 @@ plugins contain `package.json` in the list of `config` files.
|
|
|
86
86
|
|
|
87
87
|
:::tip[Summary]
|
|
88
88
|
|
|
89
|
-
Plugins
|
|
90
|
-
|
|
89
|
+
Plugins load configuration files to find referenced dependencies, and determine
|
|
90
|
+
unused and unlisted dependencies.
|
|
91
91
|
|
|
92
92
|
:::
|
|
93
93
|
|
|
@@ -100,8 +100,8 @@ dependencies.
|
|
|
100
100
|
For example, if `next` is listed as a dependency in `package.json`, the Next.js
|
|
101
101
|
plugin will automatically add multiple patterns as entry files, such as
|
|
102
102
|
`pages/**/*.{js,jsx,ts,tsx}`. If `vitest` is listed, the Vitest plugin adds
|
|
103
|
-
`**/*.{test,test-d,spec}.ts` as entry file patterns. Most plugins have
|
|
104
|
-
files configured, so you don't have to.
|
|
103
|
+
`**/*.{test,test-d,spec,spec-d}.ts` as entry file patterns. Most plugins have
|
|
104
|
+
entry files configured, so you don't have to.
|
|
105
105
|
|
|
106
106
|
It's mostly plugins for meta frameworks and test runners that have `entry` files
|
|
107
107
|
configured.
|
|
@@ -304,6 +304,23 @@ playwright test -c playwright.web.config.ts
|
|
|
304
304
|
|
|
305
305
|
Please see [script parser][10] for more details.
|
|
306
306
|
|
|
307
|
+
## Config File Location
|
|
308
|
+
|
|
309
|
+
If configuration files aren't in their default location and they are not
|
|
310
|
+
referenced through some script like `vite -c ./dir/vite.config.ts`, then make
|
|
311
|
+
sure to tell Knip about it. Two examples:
|
|
312
|
+
|
|
313
|
+
```json title="knip.jsonc"
|
|
314
|
+
{
|
|
315
|
+
"playwright": { "config": ["e2e/playwright.config.ts"] },
|
|
316
|
+
"vite": "packages/*/vite.config.ts" // shorthand without `config` and array notation
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
This is common in projects where a directory like `packages/lib` is not an
|
|
321
|
+
actual workspace with a `package.json` file. Also see [integrated monorepos][11]
|
|
322
|
+
for similar cases.
|
|
323
|
+
|
|
307
324
|
## Summary
|
|
308
325
|
|
|
309
326
|
:::tip[Summary]
|
|
@@ -327,3 +344,4 @@ Plugins are configured with two distinct types of files:
|
|
|
327
344
|
[8]: ../reference/plugins/vitest.md
|
|
328
345
|
[9]: ../guides/handling-issues.mdx#conditional-or-dynamic-dependencies
|
|
329
346
|
[10]: ../features/script-parser.md
|
|
347
|
+
[11]: ../features/integrated-monorepos.md
|
|
@@ -689,7 +689,7 @@ issue on GitHub. It'll make Knip better for everyone!
|
|
|
689
689
|
[32]: #dependencies-named-after-nodejs-builtins
|
|
690
690
|
[33]: #unlisted-binaries
|
|
691
691
|
[34]: https://github.com/webpro-nl/knip/blob/e031018e676c47d84873cc2403251c0111ef318d/packages/knip/src/constants.ts#L39-L148
|
|
692
|
-
[35]: ../features/monorepos-and-workspaces.md#
|
|
692
|
+
[35]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
693
693
|
[36]: #template-strings
|
|
694
694
|
[37]: #unrecognized-path-aliases
|
|
695
695
|
[38]: #external-aliased-imports
|
|
@@ -73,17 +73,17 @@ Other solutions to share a minimal and reproducible case may work well too,
|
|
|
73
73
|
including:
|
|
74
74
|
|
|
75
75
|
- A public repository on e.g. GitHub or GitLab.
|
|
76
|
-
- A
|
|
76
|
+
- A pull request with a new [test][9] and/or [fixture folder][10].
|
|
77
77
|
|
|
78
78
|
The goal is to have an easy and common understanding and reproduction. If you're
|
|
79
79
|
unable to create a reproduction using one of the methods described then please
|
|
80
|
-
clearly explain this in the issue or [contact me][
|
|
80
|
+
clearly explain this in the issue or [contact me][11].
|
|
81
81
|
|
|
82
82
|
## Pull Request
|
|
83
83
|
|
|
84
84
|
The optimal way is to add fixtures and failing tests to the Knip repository, and
|
|
85
85
|
open a pull request to discuss the issue! Also see [instructions for
|
|
86
|
-
development][
|
|
86
|
+
development][12].
|
|
87
87
|
|
|
88
88
|
[1]: https://github.com/webpro-nl/knip/issues?q=is%3Aissue
|
|
89
89
|
[2]: https://knip.dev/reference/known-issues
|
|
@@ -97,6 +97,7 @@ development][11].
|
|
|
97
97
|
https://stackblitz.com/github/webpro-nl/knip/tree/main/templates/issue-reproduction/monorepo
|
|
98
98
|
[7]: https://codesandbox.io
|
|
99
99
|
[8]: https://stackblitz.com
|
|
100
|
-
[9]: https://github.com/webpro-nl/knip/
|
|
101
|
-
[10]: https://github.com/webpro
|
|
102
|
-
[11]: https://github.com/webpro
|
|
100
|
+
[9]: https://github.com/webpro-nl/knip/blob/main/.github/DEVELOPMENT.md#tests
|
|
101
|
+
[10]: https://github.com/webpro-nl/knip/tree/main/packages/knip/fixtures
|
|
102
|
+
[11]: https://github.com/webpro
|
|
103
|
+
[12]: https://github.com/webpro-nl/knip/blob/main/.github/DEVELOPMENT.md
|
|
@@ -105,4 +105,4 @@ individual workspaces][6].
|
|
|
105
105
|
[3]: ../guides/handling-issues.mdx#external-libraries
|
|
106
106
|
[4]: ../reference/cli.md#--performance
|
|
107
107
|
[5]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
108
|
-
[6]: ../features/monorepos-and-workspaces.md#
|
|
108
|
+
[6]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
@@ -63,4 +63,4 @@ Also see [related tooling][2].
|
|
|
63
63
|
[23]: ../features/production-mode.md#strict-mode
|
|
64
64
|
[24]: ../guides/troubleshooting.md#trace
|
|
65
65
|
[25]: ../reference/cli.md#--watch
|
|
66
|
-
[26]: ../features/monorepos-and-workspaces.md#
|
|
66
|
+
[26]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
@@ -22,6 +22,65 @@ This FAQ is an attempt to provide some perspective on a few design decisions and
|
|
|
22
22
|
why certain things work the way they do. Here and there it's intentionally a bit
|
|
23
23
|
more in-depth than the rest of the docs.
|
|
24
24
|
|
|
25
|
+
## Why should I even bother to do all this?
|
|
26
|
+
|
|
27
|
+
Because the payoff is huge. While it might take a bit of effort to configure
|
|
28
|
+
Knip correctly initially, a clean module graph gives you absolute confidence in
|
|
29
|
+
your codebase. You can delete dead code, remove unused dependencies, and
|
|
30
|
+
refactor with certainty. It prevents the slow accumulation of technical debt and
|
|
31
|
+
keeps your project lean and fast. Once configured, Knip runs quickly in CI and
|
|
32
|
+
keeps your codebase pristine automatically.
|
|
33
|
+
|
|
34
|
+
:::tip
|
|
35
|
+
|
|
36
|
+
Try the [Knip MCP Server][1] or the [Knip Editor Extension][2]. Let your coding
|
|
37
|
+
agent use the built-in MCP Server and create a custom `knip.json` for you, so
|
|
38
|
+
you don't have to.
|
|
39
|
+
|
|
40
|
+
:::
|
|
41
|
+
|
|
42
|
+
## Common Pitfalls
|
|
43
|
+
|
|
44
|
+
### Why shouldn't I ignore or disable configuration hints?
|
|
45
|
+
|
|
46
|
+
Configuration hints are critical for building a healthy and accurate module
|
|
47
|
+
graph. They usually indicate that Knip cannot resolve a dependency, plugin, or
|
|
48
|
+
entry file. If you ignore or disable these hints, Knip's understanding of your
|
|
49
|
+
project will be incomplete, which inevitably leads to false positives (reporting
|
|
50
|
+
used code as unused). Always address configuration hints first before looking at
|
|
51
|
+
other reported issues.
|
|
52
|
+
|
|
53
|
+
### Why is it a bad idea to use `ignore` patterns like I do in ESLint?
|
|
54
|
+
|
|
55
|
+
Knip is not a regular file-based linter like ESLint. It works by analyzing the
|
|
56
|
+
entire interconnected module graph of your project. Using `ignore` patterns does
|
|
57
|
+
not exclude files from the analysis, it only suppresses the reporting of issues
|
|
58
|
+
in those files. This hides real issues and creates blind spots. Instead of
|
|
59
|
+
ignoring files, ensure your entry points and plugins are configured correctly,
|
|
60
|
+
and use `project` patterns to define the boundaries of your codebase. Read more:
|
|
61
|
+
[Configuring Project Files][3].
|
|
62
|
+
|
|
63
|
+
If you have specific exports (such as types) that are only used within the file
|
|
64
|
+
they are defined, use the [ignoreExportsUsedInFile][4] configuration option
|
|
65
|
+
rather than ignoring the file entirely.
|
|
66
|
+
|
|
67
|
+
### How should I exclude tests and development tools from the analysis?
|
|
68
|
+
|
|
69
|
+
A common mistake is trying to exclude test files, storybooks, or development
|
|
70
|
+
tools using `project` or `ignore` patterns. The correct approach is to use
|
|
71
|
+
[production mode][5]. This mode is specifically designed to strictly analyze
|
|
72
|
+
only your production source code and `dependencies`, automatically excluding
|
|
73
|
+
tests and `devDependencies` without requiring complex ignore rules.
|
|
74
|
+
|
|
75
|
+
### Why shouldn't I run `knip --fix` immediately?
|
|
76
|
+
|
|
77
|
+
Running `knip --fix` before your configuration is fully settled is dangerous. If
|
|
78
|
+
your configuration is missing entry points or has unresolved hints, Knip might
|
|
79
|
+
think perfectly valid, actively used code is unused. Auto-fixing in this state
|
|
80
|
+
can lead to deleting code that your application relies on. Always verify the
|
|
81
|
+
reported issues manually and ensure your configuration is solid before using the
|
|
82
|
+
`--fix` flag.
|
|
83
|
+
|
|
25
84
|
## Comparison
|
|
26
85
|
|
|
27
86
|
### Why isn't Knip an ESLint plugin?
|
|
@@ -53,10 +112,10 @@ Issues reported by the linter are for you to handle and review.
|
|
|
53
112
|
|
|
54
113
|
Besides those differences, Knip has a broader scope:
|
|
55
114
|
|
|
56
|
-
- Improve DX (see [less is more][
|
|
57
|
-
- Unless using [production mode][
|
|
115
|
+
- Improve DX (see [less is more][6]).
|
|
116
|
+
- Unless using [production mode][5], also lint all source code like tests,
|
|
58
117
|
scripts and Storybook stories.
|
|
59
|
-
- Handle more [types of issues][
|
|
118
|
+
- Handle more [types of issues][7] (such as unlisted dependencies).
|
|
60
119
|
|
|
61
120
|
## Synergy
|
|
62
121
|
|
|
@@ -89,13 +148,13 @@ Building up the module and dependency graphs requires non-standard module
|
|
|
89
148
|
resolution and not only static but also dynamic analysis (i.e. actually load and
|
|
90
149
|
execute modules), such as for parsers of plugins to receive the exported value
|
|
91
150
|
of dynamic tooling configuration files. Additionally, [exports consumed by
|
|
92
|
-
external libraries][
|
|
151
|
+
external libraries][8] require type information, as supported by the TypeScript
|
|
93
152
|
backend. Last but not least, shell script parsing is required to find the right
|
|
94
153
|
entry files, configuration files and dependencies accurately.
|
|
95
154
|
|
|
96
155
|
The rippling effect of plugins and recursively adding entry files and
|
|
97
156
|
dependencies to build up the graphs is also exactly what's meant by
|
|
98
|
-
["comprehensive" here][
|
|
157
|
+
["comprehensive" here][9].
|
|
99
158
|
|
|
100
159
|
## Building the graphs
|
|
101
160
|
|
|
@@ -143,7 +202,7 @@ files (`config/vitest.config.ts` and `playwright.e2e.config.ts` in the examples
|
|
|
143
202
|
above). They're recognized as configuration files and passed to their respective
|
|
144
203
|
plugins, and may contain additional entry files.
|
|
145
204
|
|
|
146
|
-
Entry files are added to the module graph. [Module resolution][
|
|
205
|
+
Entry files are added to the module graph. [Module resolution][10] might result
|
|
147
206
|
in additional entry files recursively until no more entry files are found.
|
|
148
207
|
|
|
149
208
|
### What does Knip look for in source files?
|
|
@@ -156,7 +215,7 @@ all nodes of the generated AST to find:
|
|
|
156
215
|
- Accessed properties on namespace imports and re-exports to track individual
|
|
157
216
|
export usage
|
|
158
217
|
- Calls to `require.resolve` and `import.meta.resolve`
|
|
159
|
-
- Scripts in template strings (passed to [script parser][
|
|
218
|
+
- Scripts in template strings (passed to [script parser][11])
|
|
160
219
|
|
|
161
220
|
### What's in the graphs?
|
|
162
221
|
|
|
@@ -194,7 +253,7 @@ there are a few issues with this approach:
|
|
|
194
253
|
|
|
195
254
|
- It requires lockfile parsing for each lockfile format and version of each
|
|
196
255
|
package manager.
|
|
197
|
-
- The lockfile doesn't contain whether the package [has types included][
|
|
256
|
+
- The lockfile doesn't contain whether the package [has types included][12].
|
|
198
257
|
|
|
199
258
|
## Module Resolution
|
|
200
259
|
|
|
@@ -215,12 +274,12 @@ seem to meet all requirements to be usable on its own by Knip:
|
|
|
215
274
|
`module.js`
|
|
216
275
|
|
|
217
276
|
A few strategies have been tried and tweaked, and Knip currently uses a
|
|
218
|
-
combination of [oxc-resolver][
|
|
277
|
+
combination of [oxc-resolver][13], the TypeScript module resolver and a few
|
|
219
278
|
customizations. This single custom module resolver function is hooked into the
|
|
220
279
|
TypeScript compiler and language service hosts.
|
|
221
280
|
|
|
222
|
-
Everything else is handled by `oxc-resolver` for things like [script
|
|
223
|
-
and resolving references to files in other workspaces.
|
|
281
|
+
Everything else is handled by `oxc-resolver` for things like [script
|
|
282
|
+
parsing][11] and resolving references to files in other workspaces.
|
|
224
283
|
|
|
225
284
|
### How does Knip handle non-standard import syntax?
|
|
226
285
|
|
|
@@ -250,7 +309,7 @@ file. They're not a concept in Knip.
|
|
|
250
309
|
|
|
251
310
|
A TypeScript program has a 1-to-1 relationship with workspaces if they're
|
|
252
311
|
analyzed in isolation. However, by default Knip optimizes for performance and
|
|
253
|
-
utilizes [workspace sharing][
|
|
312
|
+
utilizes [workspace sharing][14]. That's why debug output contains messages like
|
|
254
313
|
"Installed 2 programs for 29 workspaces".
|
|
255
314
|
|
|
256
315
|
### Why doesn't Knip match my TypeScript project structure?
|
|
@@ -282,7 +341,7 @@ Knip shares the files of multiple workspaces in a single program if their
|
|
|
282
341
|
configuration allows it. This optimization is enabled by default, while it also
|
|
283
342
|
allows the module resolver (one per program) to do some more caching.
|
|
284
343
|
|
|
285
|
-
Also see [workspace sharing][
|
|
344
|
+
Also see [workspace sharing][14].
|
|
286
345
|
|
|
287
346
|
### Why doesn't Knip just use `ts.findReferences`?
|
|
288
347
|
|
|
@@ -298,7 +357,7 @@ comprehensive graph include:
|
|
|
298
357
|
Without sacrificing these benefits, Knip does use `ts.findReferences` to find
|
|
299
358
|
references to class members (i.e. when the issue type `classMembers` is
|
|
300
359
|
included). In case analysis of exports requires type information of external
|
|
301
|
-
dependencies, the [`--include-libs ` flag][
|
|
360
|
+
dependencies, the [`--include-libs ` flag][8] will trigger the same.
|
|
302
361
|
|
|
303
362
|
### Why can't I use path aliases to reference other workspaces?
|
|
304
363
|
|
|
@@ -310,19 +369,19 @@ The recommendation and best practice is to list such workspaces/dependencies in
|
|
|
310
369
|
`package.json`, and import them as such. Other tooling should not have any
|
|
311
370
|
issues with this standard approach either.
|
|
312
371
|
|
|
313
|
-
Also see the example in [TypeScript path aliases in monorepos][
|
|
372
|
+
Also see the example in [TypeScript path aliases in monorepos][15].
|
|
314
373
|
|
|
315
374
|
### What's up with that configurable `tsconfig.json` location?
|
|
316
375
|
|
|
317
376
|
There's a difference between `--tsConfig [file]` as a CLI argument and the
|
|
318
377
|
`typescript.config` option in Knip configuration.
|
|
319
378
|
|
|
320
|
-
The [`--tsConfig [file]` option][
|
|
379
|
+
The [`--tsConfig [file]` option][16] is used to provide an alternative location
|
|
321
380
|
for the default root `tsconfig.json` file. Relevant `compilerOptions` include
|
|
322
381
|
`paths` and `moduleResolution`. This setting is only available at the root
|
|
323
382
|
level.
|
|
324
383
|
|
|
325
|
-
On the other hand, the [`config` option of the plugin][
|
|
384
|
+
On the other hand, the [`config` option of the plugin][17] can be set per
|
|
326
385
|
workspace. The TypeScript plugin extracts referenced external dependencies such
|
|
327
386
|
as those in `extends`, `compilerOptions.types` and JSX settings:
|
|
328
387
|
|
|
@@ -346,7 +405,7 @@ From this example, Knip can determine whether the `@tsconfig/node20` and
|
|
|
346
405
|
for `tsconfig.json` can be set per workspace.
|
|
347
406
|
- In case path aliases from `compilerOptions.paths` aren't picked up by Knip,
|
|
348
407
|
either use `--tsConfig [file]` to target a different `tsconfig.json`, or
|
|
349
|
-
manually add [paths][
|
|
408
|
+
manually add [paths][18] to the Knip configuration. The latter can be done per
|
|
350
409
|
workspace.
|
|
351
410
|
|
|
352
411
|
## Compilers
|
|
@@ -369,7 +428,7 @@ other file types.
|
|
|
369
428
|
Knip comes with basic "compilers" for a few common non-standard file types.
|
|
370
429
|
They're not actual compilers, they're regular expressions only to extract import
|
|
371
430
|
statements. Override the built-in Vue "compiler" with the real one in your
|
|
372
|
-
project. Also see the answer to the previous question and [Compilers][
|
|
431
|
+
project. Also see the answer to the previous question and [Compilers][19].
|
|
373
432
|
|
|
374
433
|
## Miscellaneous
|
|
375
434
|
|
|
@@ -389,7 +448,7 @@ Which mode should've been the default? They both have their merits:
|
|
|
389
448
|
tooling, including most issues found in production mode. This mode has the
|
|
390
449
|
most impact on DX, for the same reason.
|
|
391
450
|
|
|
392
|
-
Also see [production mode][
|
|
451
|
+
Also see [production mode][5].
|
|
393
452
|
|
|
394
453
|
### Why doesn't Knip have...?
|
|
395
454
|
|
|
@@ -410,21 +469,25 @@ Examples of features that have been requested include:
|
|
|
410
469
|
|
|
411
470
|
These are all interesting ideas, but most increase the API surface area, and all
|
|
412
471
|
require more development efforts and maintenance. Time is limited and
|
|
413
|
-
[sponsorships][
|
|
414
|
-
|
|
415
|
-
[1]: ../
|
|
416
|
-
[2]: ../
|
|
417
|
-
[3]:
|
|
418
|
-
[4]: ../
|
|
419
|
-
[5]: ../
|
|
420
|
-
[6]: #
|
|
421
|
-
[7]:
|
|
422
|
-
[8]: ../guides/handling-issues.mdx#
|
|
423
|
-
[9]:
|
|
424
|
-
[10]:
|
|
425
|
-
[11]: ../
|
|
426
|
-
[12]: ../
|
|
427
|
-
[13]:
|
|
428
|
-
[14]: ../
|
|
429
|
-
[15]: ../
|
|
430
|
-
[16]: /
|
|
472
|
+
[sponsorships][20] currently don't cover - this can change though!
|
|
473
|
+
|
|
474
|
+
[1]: ../reference/integrations.md#mcp-server
|
|
475
|
+
[2]: ../reference/integrations.md#vs-code-extension
|
|
476
|
+
[3]: ../guides/configuring-project-files.md
|
|
477
|
+
[4]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
478
|
+
[5]: ../features/production-mode.md
|
|
479
|
+
[6]: ../explanations/why-use-knip.md#less-is-more
|
|
480
|
+
[7]: ./issue-types.md
|
|
481
|
+
[8]: ../guides/handling-issues.mdx#external-libraries
|
|
482
|
+
[9]: ../explanations/why-use-knip.md#comprehensive
|
|
483
|
+
[10]: #module-resolution
|
|
484
|
+
[11]: ../features/script-parser.md
|
|
485
|
+
[12]: ../guides/handling-issues.mdx#type-definition-packages
|
|
486
|
+
[13]: https://oxc.rs/docs/guide/usage/resolver.html
|
|
487
|
+
[14]: ../guides/performance.md#workspace-sharing
|
|
488
|
+
[15]: ../guides/handling-issues.mdx#typescript-path-aliases-in-monorepos
|
|
489
|
+
[16]: ../reference/cli.md#--tsconfig-file
|
|
490
|
+
[17]: ../explanations/plugins.md#configuration-files
|
|
491
|
+
[18]: ../reference/configuration.md#paths
|
|
492
|
+
[19]: ../features/compilers.md
|
|
493
|
+
[20]: /sponsors
|
|
@@ -30,7 +30,7 @@ Example:
|
|
|
30
30
|
export const myUnusedExport = 1;
|
|
31
31
|
|
|
32
32
|
/** @lintignore */
|
|
33
|
-
import Unresolved from
|
|
33
|
+
import Unresolved from "./generated/lib.js";
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
And then include (`+`) or exclude (`-`) these tagged exports from the report
|
|
@@ -42,6 +42,17 @@ knip --tags=-lintignore,-internal
|
|
|
42
42
|
|
|
43
43
|
Tags can also be [configured in `knip.json`][2].
|
|
44
44
|
|
|
45
|
+
When an excluded tag is no longer necessary because the export is actually used,
|
|
46
|
+
Knip reports a **tag hint**:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
Tag hints (1)
|
|
50
|
+
ignored unimported.ts Unused tag in unimported.ts: ignored → @custom
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This helps you clean up tags that were added to suppress issues that have since
|
|
54
|
+
been resolved.
|
|
55
|
+
|
|
45
56
|
## `@public`
|
|
46
57
|
|
|
47
58
|
By default, Knip reports unused exports in non-entry files.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Plugins (
|
|
2
|
+
title: Plugins (137)
|
|
3
3
|
tableOfContents: false
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -32,6 +32,7 @@ tableOfContents: false
|
|
|
32
32
|
- [Drizzle](/reference/plugins/drizzle "Drizzle")
|
|
33
33
|
- [Eleventy](/reference/plugins/eleventy "Eleventy")
|
|
34
34
|
- [ESLint](/reference/plugins/eslint "ESLint")
|
|
35
|
+
- [execa](/reference/plugins/execa "execa")
|
|
35
36
|
- [Expo](/reference/plugins/expo "Expo")
|
|
36
37
|
- [Expressive Code](/reference/plugins/expressive-code "Expressive Code")
|
|
37
38
|
- [Gatsby](/reference/plugins/gatsby "Gatsby")
|
|
@@ -75,16 +76,20 @@ tableOfContents: false
|
|
|
75
76
|
- [oclif](/reference/plugins/oclif "oclif")
|
|
76
77
|
- [Oxlint](/reference/plugins/oxlint "Oxlint")
|
|
77
78
|
- [Parcel](/reference/plugins/parcel "Parcel")
|
|
79
|
+
- [Payload CMS](/reference/plugins/payload "Payload CMS")
|
|
78
80
|
- [Playwright](/reference/plugins/playwright "Playwright")
|
|
79
81
|
- [Playwright for components](/reference/plugins/playwright-ct "Playwright for components")
|
|
80
82
|
- [playwright-test](/reference/plugins/playwright-test "playwright-test")
|
|
81
83
|
- [Plop](/reference/plugins/plop "Plop")
|
|
84
|
+
- [pm2](/reference/plugins/pm2 "pm2")
|
|
82
85
|
- [pnpm](/reference/plugins/pnpm "pnpm")
|
|
83
86
|
- [PostCSS](/reference/plugins/postcss "PostCSS")
|
|
84
87
|
- [Preconstruct](/reference/plugins/preconstruct "Preconstruct")
|
|
85
88
|
- [Prettier](/reference/plugins/prettier "Prettier")
|
|
86
89
|
- [Prisma](/reference/plugins/prisma "Prisma")
|
|
90
|
+
- [Qwik](/reference/plugins/qwik "Qwik")
|
|
87
91
|
- [React Cosmos](/reference/plugins/react-cosmos "React Cosmos")
|
|
92
|
+
- [React Native](/reference/plugins/react-native "React Native")
|
|
88
93
|
- [React Router](/reference/plugins/react-router "React Router")
|
|
89
94
|
- [Relay](/reference/plugins/relay "Relay")
|
|
90
95
|
- [Release It!](/reference/plugins/release-it "Release It!")
|
|
@@ -135,6 +140,7 @@ tableOfContents: false
|
|
|
135
140
|
- [xo](/reference/plugins/xo "xo")
|
|
136
141
|
- [Yarn](/reference/plugins/yarn "Yarn")
|
|
137
142
|
- [yorkie](/reference/plugins/yorkie "yorkie")
|
|
143
|
+
- [zx](/reference/plugins/zx "zx")
|
|
138
144
|
|
|
139
145
|
|
|
140
146
|
:::
|
|
@@ -365,7 +365,7 @@ The script adds the plugin to the JSON Schema and type definitions.
|
|
|
365
365
|
Run the test for your new plugin using one of the following commands:
|
|
366
366
|
|
|
367
367
|
```sh
|
|
368
|
-
|
|
368
|
+
node --test test/plugins/tool.test.ts
|
|
369
369
|
bun test test/plugins/tool.test.ts
|
|
370
370
|
```
|
|
371
371
|
|