@knip/mcp 0.0.12 → 0.0.13
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/explanations/plugins.md +8 -1
- package/src/docs/docs/guides/configuring-project-files.md +13 -13
- package/src/docs/docs/guides/handling-issues.mdx +104 -57
- package/src/docs/docs/guides/troubleshooting.md +4 -7
- package/src/docs/docs/overview/configuration.md +6 -6
- package/src/docs/docs/reference/configuration.md +17 -7
- package/src/docs/docs/reference/known-issues.md +32 -19
- package/src/docs/docs/reference/plugins/bun.md +0 -20
- package/src/docs/docs/reference/plugins/lefthook.md +4 -4
- package/src/docs/docs/reference/plugins/node.md +2 -2
- package/src/docs/docs/reference/plugins/nx.md +1 -1
- package/src/docs/docs/reference/plugins/playwright-ct.md +3 -3
- package/src/docs/docs/reference/plugins/vitepress.md +34 -0
- package/src/docs/docs/sponsors.mdx +2 -3
- package/src/texts.js +19 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knip/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Knip MCP Server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"author": "Lars Kappert <lars@webpro.nl>",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
30
30
|
"zod": "^4.1.11",
|
|
31
|
-
"knip": "^5.
|
|
31
|
+
"knip": "^5.79.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.18.0"
|
|
@@ -73,7 +73,7 @@ export default defineConfig({
|
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
The Vitest plugin reads this configuration and
|
|
76
|
+
The Vitest plugin reads this configuration and returns two dependencies:
|
|
77
77
|
|
|
78
78
|
- `@vitest/coverage-istanbul`
|
|
79
79
|
- `vitest-environment-happy-dom`
|
|
@@ -283,6 +283,12 @@ automatically added as `entry` files for Knip to **statically** resolve the
|
|
|
283
283
|
|
|
284
284
|
Additionally, `./setup-tests.ts` will be added as an `entry` file.
|
|
285
285
|
|
|
286
|
+
:::note
|
|
287
|
+
|
|
288
|
+
When plugins dynamically load configuration files, conditional dependencies may not be detected if the condition evaluates differently during analysis. See [conditional or dynamic dependencies][10] for details and workarounds.
|
|
289
|
+
|
|
290
|
+
:::
|
|
291
|
+
|
|
286
292
|
## Command-Line Arguments
|
|
287
293
|
|
|
288
294
|
Plugins may define the arguments where Knip should look for entry files,
|
|
@@ -317,3 +323,4 @@ Plugins are configured with two distinct types of files:
|
|
|
317
323
|
[7]: ../reference/plugins/eslint.md
|
|
318
324
|
[8]: ../reference/plugins/vitest.md
|
|
319
325
|
[9]: ../features/script-parser.md
|
|
326
|
+
[10]: ../guides/handling-issues.mdx#conditional-or-dynamic-dependencies
|
|
@@ -11,7 +11,7 @@ Knip faster:
|
|
|
11
11
|
- Start with defaults. Only add targeted `entry` overrides when needed.
|
|
12
12
|
- Use `project` patterns (with negations) to define the scope for Knip.
|
|
13
13
|
- Use production mode to exclude tests and other non-production files.
|
|
14
|
-
- Use `ignore` only to suppress issues in specific files
|
|
14
|
+
- Use `ignore` only to suppress issues in specific files; it does not exclude
|
|
15
15
|
files from analysis.
|
|
16
16
|
|
|
17
17
|
Let's dive in and expand on all of these.
|
|
@@ -41,8 +41,8 @@ and adjust `project` to fit your codebase.
|
|
|
41
41
|
Use negated `project` patterns to precisely include/exclude files for unused
|
|
42
42
|
files detection.
|
|
43
43
|
|
|
44
|
-
Use `ignore` to suppress issues in matching files; it does not
|
|
45
|
-
|
|
44
|
+
Use `ignore` to suppress issues in matching files; it does not exclude files
|
|
45
|
+
from analysis.
|
|
46
46
|
|
|
47
47
|
:::
|
|
48
48
|
|
|
@@ -87,12 +87,12 @@ positives)? Use negated `project` patterns:
|
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Why is
|
|
90
|
+
Why this is better:
|
|
91
91
|
|
|
92
|
-
- `project` defines
|
|
93
|
-
|
|
92
|
+
- `project` defines what belongs to the codebase, so build outputs are excluded
|
|
93
|
+
from analysis and unused file detection
|
|
94
94
|
- `ignore` is for the few files that should be analyzed but contain exceptions
|
|
95
|
-
-
|
|
95
|
+
- Improves performance by analyzing fewer files
|
|
96
96
|
|
|
97
97
|
## Ignore issues in specific files
|
|
98
98
|
|
|
@@ -127,8 +127,8 @@ instead.
|
|
|
127
127
|
}
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
Why not: `ignore`
|
|
131
|
-
|
|
130
|
+
Why not: `ignore` hides issues from the report; it does not exclude files from
|
|
131
|
+
analysis.
|
|
132
132
|
|
|
133
133
|
❌ Also don't do this:
|
|
134
134
|
|
|
@@ -138,8 +138,8 @@ from analysis.
|
|
|
138
138
|
}
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
Why not: plugins
|
|
142
|
-
|
|
141
|
+
Why not: plugins add test files as `entry` files; you can't and shouldn't
|
|
142
|
+
override that globally.
|
|
143
143
|
|
|
144
144
|
❌ Or this:
|
|
145
145
|
|
|
@@ -149,8 +149,8 @@ and shouldn't override that globally.
|
|
|
149
149
|
}
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
Why not: `project` is
|
|
153
|
-
|
|
152
|
+
Why not: `project` is for unused file detection; negating test files is
|
|
153
|
+
ineffective because they are `entry` files.
|
|
154
154
|
|
|
155
155
|
✅ Do this instead:
|
|
156
156
|
|
|
@@ -6,16 +6,11 @@ sidebar:
|
|
|
6
6
|
|
|
7
7
|
import { Tabs, TabItem } from '@astrojs/starlight/components';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
some initial configuration.
|
|
9
|
+
Issues reported by Knip may contain false positives, but also tons of useful
|
|
10
|
+
information. Getting the most out of Knip may require some configuration.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
If you start out using Knip in a large project and have a long report, it makes
|
|
17
|
-
sense to go over the issue types one by one. For instance, reducing the number
|
|
18
|
-
of unused files will also reduce the number of unused dependencies.
|
|
12
|
+
Go over the issue types one by one. For instance, reducing the number of unused
|
|
13
|
+
files will also reduce the number of unused dependencies.
|
|
19
14
|
|
|
20
15
|
1. [Unused files][1]
|
|
21
16
|
2. [Unused dependencies][2]
|
|
@@ -124,8 +119,8 @@ Entry files referenced in HTML files (e.g. `<script src="production.js">`).
|
|
|
124
119
|
compiler to extract and resolve the value of `<script src>` elements.
|
|
125
120
|
|
|
126
121
|
Knip has support for some popular framework formats through [compilers][19], and
|
|
127
|
-
additional compilers can be added for
|
|
128
|
-
|
|
122
|
+
additional compilers can be added for any file type. The recommended solution is
|
|
123
|
+
usually to add the file as shown in each example as an `entry` file.
|
|
129
124
|
|
|
130
125
|
### Missing plugin
|
|
131
126
|
|
|
@@ -253,6 +248,7 @@ The most common causes for unused dependencies include:
|
|
|
253
248
|
- [Missing or incomplete plugins][27]
|
|
254
249
|
- [Unrecognized references][28]
|
|
255
250
|
- [Type Definition Packages][29]
|
|
251
|
+
- [Dependencies named after Node.js builtins][30]
|
|
256
252
|
|
|
257
253
|
Use `--dependencies` to [filter the report][15] and focus only on issues related
|
|
258
254
|
to dependencies:
|
|
@@ -264,8 +260,8 @@ knip --dependencies
|
|
|
264
260
|
:::caution[Monorepo]
|
|
265
261
|
|
|
266
262
|
In a monorepo, a dependency is unused in the root workspace's `package.json` if
|
|
267
|
-
it's also listed in
|
|
268
|
-
|
|
263
|
+
it's also listed in a descendant workspace, and referenced only in the
|
|
264
|
+
descendant workspace.
|
|
269
265
|
|
|
270
266
|
:::
|
|
271
267
|
|
|
@@ -288,7 +284,54 @@ so it's a false positive and incorrectly reported as unused.
|
|
|
288
284
|
like a plugin could solve it, a last resort is to use [ignoreDependencies][22].
|
|
289
285
|
|
|
290
286
|
If a binary (or "executable") is referenced you'll want to use `ignoreBinaries`
|
|
291
|
-
instead. See [unlisted binaries][
|
|
287
|
+
instead. See [unlisted binaries][31].
|
|
288
|
+
|
|
289
|
+
### Dependencies named after Node.js builtins
|
|
290
|
+
|
|
291
|
+
Some packages have the same name as a Node.js builtin (for instance `buffer` or
|
|
292
|
+
`process`).
|
|
293
|
+
|
|
294
|
+
**Solution**: if Knip reports such a dependency as unused, add it to
|
|
295
|
+
[ignoreDependencies][22].
|
|
296
|
+
|
|
297
|
+
#### Conditional or dynamic dependencies
|
|
298
|
+
|
|
299
|
+
Dependencies added conditionally in configuration files may not be detected by
|
|
300
|
+
Knip. This happens because Knip loads and executes config files, and conditional
|
|
301
|
+
logic may evaluate differently during analysis.
|
|
302
|
+
|
|
303
|
+
For example, this Playwright configuration conditionally adds a reporter:
|
|
304
|
+
|
|
305
|
+
```ts title="playwright.config.ts"
|
|
306
|
+
import { defineConfig } from '@playwright/test';
|
|
307
|
+
|
|
308
|
+
const reporters: any[] = [['list']];
|
|
309
|
+
if (process.env.REPORT_PORTAL_ENABLED) {
|
|
310
|
+
reporters.push(['@reportportal/agent-js-playwright', config]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export default defineConfig({
|
|
314
|
+
reporter: reporters,
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
If `process.env.REPORT_PORTAL_ENABLED` evaluates to `false` when Knip runs, the
|
|
319
|
+
`@reportportal/agent-js-playwright` dependency won't be detected and may be
|
|
320
|
+
reported as unused.
|
|
321
|
+
|
|
322
|
+
This limitation exists because Knip executes configuration files to parse their exported value.
|
|
323
|
+
While Knip can parse configuration files statically using AST (Abstract
|
|
324
|
+
Syntax Tree) analysis, this approach becomes complex very quickly and most of
|
|
325
|
+
the time it is easier to use the [`ignoreDependencies`][22] configuration option
|
|
326
|
+
for conditionals.
|
|
327
|
+
|
|
328
|
+
```json title="knip.json"
|
|
329
|
+
{
|
|
330
|
+
"ignoreDependencies": ["@reportportal/agent-js-playwright"]
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
This pattern can be applied to any plugin that loads configuration files.
|
|
292
335
|
|
|
293
336
|
### Type Definition Packages
|
|
294
337
|
|
|
@@ -349,7 +392,7 @@ reported as an unlisted binary as there is no package that contains it.
|
|
|
349
392
|
|
|
350
393
|
Binaries that are installed on the OS already and thus likely not meant to be
|
|
351
394
|
installed from npm are not reported as unlisted (details: [list of ignored
|
|
352
|
-
binaries in source][
|
|
395
|
+
binaries in source][32]).
|
|
353
396
|
|
|
354
397
|
#### Missing binaries
|
|
355
398
|
|
|
@@ -359,7 +402,7 @@ either the way your package manager installs dependencies and binaries, or by
|
|
|
359
402
|
not running Knip from the root of the repository.
|
|
360
403
|
|
|
361
404
|
**Solution**: run Knip from the project root. If needed, [lint workspaces
|
|
362
|
-
individually][
|
|
405
|
+
individually][33].
|
|
363
406
|
|
|
364
407
|
Sometimes binaries and how they're reported can be a bit confusing. See this
|
|
365
408
|
example:
|
|
@@ -395,10 +438,10 @@ or consider the binary and package(s) referenced, respectively.
|
|
|
395
438
|
Knip may ignore or be unable to resolve an import specifier or dependency
|
|
396
439
|
references. The most common causes for unresolved imports:
|
|
397
440
|
|
|
398
|
-
- [Template strings][
|
|
441
|
+
- [Template strings][34]
|
|
399
442
|
- [Extensionless imports][28]
|
|
400
|
-
- [Unrecognized path aliases][
|
|
401
|
-
- [External aliased imports][
|
|
443
|
+
- [Unrecognized path aliases][35]
|
|
444
|
+
- [External aliased imports][36]
|
|
402
445
|
|
|
403
446
|
### Template strings
|
|
404
447
|
|
|
@@ -435,11 +478,11 @@ similar to how standard ES Modules specifies file extensions are necessary.
|
|
|
435
478
|
|
|
436
479
|
### Unrecognized path aliases
|
|
437
480
|
|
|
438
|
-
Knip considers TS config path aliases and [paths configured in knip.json][
|
|
481
|
+
Knip considers TS config path aliases and [paths configured in knip.json][37],
|
|
439
482
|
but not those in e.g. Webpack or Vite configurations.
|
|
440
483
|
|
|
441
|
-
**Solution**: configure [paths][
|
|
442
|
-
[`ignoreUnresolved`][
|
|
484
|
+
**Solution**: configure [paths][37] or try relative imports. Otherwise, use
|
|
485
|
+
[`ignoreUnresolved`][38] as a last resort.
|
|
443
486
|
|
|
444
487
|
### External aliased imports
|
|
445
488
|
|
|
@@ -458,9 +501,9 @@ option][13] to tell Knip where to find the icon types:
|
|
|
458
501
|
```
|
|
459
502
|
|
|
460
503
|
Where `[framework]` is the name of the framework you're using (see [available
|
|
461
|
-
types][
|
|
504
|
+
types][39]).
|
|
462
505
|
|
|
463
|
-
**Solution**: try [--include-libs][
|
|
506
|
+
**Solution**: try [--include-libs][40] or configure [paths][37].
|
|
464
507
|
|
|
465
508
|
## Unused exports
|
|
466
509
|
|
|
@@ -468,8 +511,8 @@ By default, Knip does not report unused exports of `entry` files.
|
|
|
468
511
|
|
|
469
512
|
The most common causes for unused exports include:
|
|
470
513
|
|
|
471
|
-
- [Namespace enumerations][
|
|
472
|
-
- [External libraries][
|
|
514
|
+
- [Namespace enumerations][41]
|
|
515
|
+
- [External libraries][40]
|
|
473
516
|
|
|
474
517
|
Use the `--exports` flag to [filter][15] and focus only on issues related to
|
|
475
518
|
exports:
|
|
@@ -478,7 +521,7 @@ exports:
|
|
|
478
521
|
knip --exports
|
|
479
522
|
```
|
|
480
523
|
|
|
481
|
-
Use [includeEntryExports][
|
|
524
|
+
Use [includeEntryExports][42] to report unused exports of entry files as well.
|
|
482
525
|
This can be set per workspace.
|
|
483
526
|
|
|
484
527
|
### Namespace enumerations
|
|
@@ -490,7 +533,7 @@ are then **not** reported.
|
|
|
490
533
|
**Solution**: if all exports on imported namespaces should be considered
|
|
491
534
|
individually, include the `nsExports` issue type to disable the heuristic.
|
|
492
535
|
|
|
493
|
-
See [namespace imports][
|
|
536
|
+
See [namespace imports][43] to see all related patterns.
|
|
494
537
|
|
|
495
538
|
### External libraries
|
|
496
539
|
|
|
@@ -510,6 +553,7 @@ non-standard consumption of your exports? Here's an example:
|
|
|
510
553
|
resolveComponent: components => components.Orange,
|
|
511
554
|
});
|
|
512
555
|
```
|
|
556
|
+
|
|
513
557
|
</TabItem>
|
|
514
558
|
|
|
515
559
|
<TabItem label="components.js">
|
|
@@ -526,22 +570,22 @@ Knip does not include external type definitions by default so it won't see the
|
|
|
526
570
|
export being referenced.
|
|
527
571
|
|
|
528
572
|
**Solution**: include the type definitions of external libraries with the
|
|
529
|
-
[--include-libs][
|
|
573
|
+
[--include-libs][44] flag:
|
|
530
574
|
|
|
531
575
|
```shell
|
|
532
576
|
knip --include-libs
|
|
533
577
|
```
|
|
534
578
|
|
|
535
579
|
This comes at a performance and memory penalty, but should give better results
|
|
536
|
-
if you need it. This flag is implied when [classMembers][
|
|
580
|
+
if you need it. This flag is implied when [classMembers][45] are included (that
|
|
537
581
|
feature comes with roughly the same performance penalty).
|
|
538
582
|
|
|
539
583
|
### Exclude exports from the report
|
|
540
584
|
|
|
541
585
|
To exclude false positives from the report, there are a few options:
|
|
542
586
|
|
|
543
|
-
- [Ignore exports used in file][
|
|
544
|
-
- Individual exports can be [tagged using JSDoc syntax][
|
|
587
|
+
- [Ignore exports used in file][46] for exports used internally.
|
|
588
|
+
- Individual exports can be [tagged using JSDoc syntax][47].
|
|
545
589
|
- Have the export in an entry file:
|
|
546
590
|
- Add the file to the `entry` file patterns array in the configuration.
|
|
547
591
|
- Move the export(s) to an entry file.
|
|
@@ -551,7 +595,7 @@ To exclude false positives from the report, there are a few options:
|
|
|
551
595
|
### Missing unused exports?
|
|
552
596
|
|
|
553
597
|
Did you expect certain exports in the report, but are they missing? They might
|
|
554
|
-
be exported from an entry file. In that case, use [--include-entry-exports][
|
|
598
|
+
be exported from an entry file. In that case, use [--include-entry-exports][42]
|
|
555
599
|
to make Knip also report unused exports in entry files.
|
|
556
600
|
|
|
557
601
|
The exports of non-standard extensions like `.astro`, `.mdx`, `.vue` or
|
|
@@ -570,10 +614,10 @@ knip --include classMembers
|
|
|
570
614
|
This option is also available in the Knip configuration file. Note that this
|
|
571
615
|
feature comes at a cost: linting will take more time and more memory.
|
|
572
616
|
|
|
573
|
-
Individual class members can be [tagged using JSDoc syntax][
|
|
617
|
+
Individual class members can be [tagged using JSDoc syntax][47].
|
|
574
618
|
|
|
575
619
|
Classes exported from entry files are ignored, and so are their members. Use
|
|
576
|
-
[--include-entry-exports][
|
|
620
|
+
[--include-entry-exports][42] to make Knip also report members of unused exports
|
|
577
621
|
in entry files.
|
|
578
622
|
|
|
579
623
|
### Enum members
|
|
@@ -585,16 +629,16 @@ Reporting such members can be disabled:
|
|
|
585
629
|
knip --exclude enumMembers
|
|
586
630
|
```
|
|
587
631
|
|
|
588
|
-
Individual enum members can be [tagged using JSDoc syntax][
|
|
632
|
+
Individual enum members can be [tagged using JSDoc syntax][47].
|
|
589
633
|
|
|
590
634
|
Enums exported from entry files are ignored, and so are their members. Use
|
|
591
|
-
[--include-entry-exports][
|
|
635
|
+
[--include-entry-exports][42] to make Knip also report members of unused exports
|
|
592
636
|
in entry files.
|
|
593
637
|
|
|
594
638
|
## Feedback or false positives?
|
|
595
639
|
|
|
596
640
|
If you believe Knip incorrectly reports something as unused (i.e. there's a
|
|
597
|
-
false positive), feel free to create a [minimal reproduction][
|
|
641
|
+
false positive), feel free to create a [minimal reproduction][48] and open an
|
|
598
642
|
issue on GitHub. It'll make Knip better for everyone!
|
|
599
643
|
|
|
600
644
|
[1]: #unused-files
|
|
@@ -621,26 +665,29 @@ issue on GitHub. It'll make Knip better for everyone!
|
|
|
621
665
|
[22]: ../reference/configuration.md#ignoredependencies
|
|
622
666
|
[23]: ../explanations/plugins.md#entry-files
|
|
623
667
|
[24]: ../explanations/entry-files.md#plugins
|
|
624
|
-
[25]:
|
|
668
|
+
[25]:
|
|
669
|
+
../reference/faq.md#why-cant-i-use-path-aliases-to-reference-other-workspaces
|
|
625
670
|
[26]: ../features/integrated-monorepos.md
|
|
626
671
|
[27]: #missing-or-incomplete-plugin
|
|
627
672
|
[28]: #unrecognized-reference
|
|
628
673
|
[29]: #type-definition-packages
|
|
629
|
-
[30]: #
|
|
630
|
-
[31]:
|
|
631
|
-
[32]:
|
|
632
|
-
|
|
633
|
-
[
|
|
634
|
-
[
|
|
635
|
-
[
|
|
636
|
-
[
|
|
637
|
-
[
|
|
638
|
-
[
|
|
639
|
-
[
|
|
640
|
-
[
|
|
641
|
-
[
|
|
642
|
-
[
|
|
643
|
-
[
|
|
644
|
-
[
|
|
645
|
-
[
|
|
646
|
-
[
|
|
674
|
+
[30]: #dependencies-named-after-nodejs-builtins
|
|
675
|
+
[31]: #unlisted-binaries
|
|
676
|
+
[32]:
|
|
677
|
+
https://github.com/webpro-nl/knip/blob/b70958a58ea255ee7a7831e404786da807ca93d7/packages/knip/src/constants.ts#L37-L139
|
|
678
|
+
[33]: ../features/monorepos-and-workspaces.md#lint-a-single-workspace
|
|
679
|
+
[34]: #template-strings
|
|
680
|
+
[35]: #unrecognized-path-aliases
|
|
681
|
+
[36]: #external-aliased-imports
|
|
682
|
+
[37]: ../reference/configuration.md#paths
|
|
683
|
+
[38]: ../reference/configuration.md#ignoreunresolved
|
|
684
|
+
[39]: #build-artifacts-and-ignored-files
|
|
685
|
+
[40]: #external-libraries
|
|
686
|
+
[41]: #namespace-enumerations
|
|
687
|
+
[42]: ../reference/configuration.md#includeentryexports
|
|
688
|
+
[43]: ../guides/namespace-imports.md
|
|
689
|
+
[44]: ../reference/cli#--include-libs
|
|
690
|
+
[45]: #class-members
|
|
691
|
+
[46]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
692
|
+
[47]: ../reference/jsdoc-tsdoc-tags.md
|
|
693
|
+
[48]: ../guides/issue-reproduction
|
|
@@ -23,8 +23,7 @@ Knip is intentionally strict to maximize its potential. It may initially report
|
|
|
23
23
|
many unused files. However, getting this right will result in great reports and
|
|
24
24
|
tidy codebases.
|
|
25
25
|
|
|
26
|
-
If it doesn't
|
|
27
|
-
change go a long way towards success.
|
|
26
|
+
If it doesn't work out at first, a small change can go a long way.
|
|
28
27
|
|
|
29
28
|
:::
|
|
30
29
|
|
|
@@ -33,9 +32,8 @@ change go a long way towards success.
|
|
|
33
32
|
Knip reports lint issues in your codebase. See [handling issues][5] to deal with
|
|
34
33
|
the reported issues.
|
|
35
34
|
|
|
36
|
-
If
|
|
37
|
-
|
|
38
|
-
reproduction][6] first.
|
|
35
|
+
If you're considering filing an issue, please read [issue reproduction][6]
|
|
36
|
+
first.
|
|
39
37
|
|
|
40
38
|
Exit code 1 indicates a successful run, but lint issues were found.
|
|
41
39
|
|
|
@@ -47,8 +45,7 @@ See [known issues][7] as it may be listed there and a workaround may be
|
|
|
47
45
|
available. If it isn't clear what's throwing the exception, try another run with
|
|
48
46
|
`--debug` to locate the cause of the issue with more details.
|
|
49
47
|
|
|
50
|
-
If
|
|
51
|
-
do! It'll make Knip better for everyone. Please read [issue reproduction][6]
|
|
48
|
+
If you're considering filing an issue, please read [issue reproduction][6]
|
|
52
49
|
first.
|
|
53
50
|
|
|
54
51
|
Exit code 2 indicates an exception was thrown by Knip.
|
|
@@ -52,10 +52,9 @@ folder:
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
from the analysis. See [configuring project files][1] for details.
|
|
55
|
+
The set of `project` files determines the analysis scope. Use negated `project`
|
|
56
|
+
patterns to exclude files from the analysis. See [configuring project files][1]
|
|
57
|
+
for details.
|
|
59
58
|
|
|
60
59
|
The values you set override the default values, they are not merged.
|
|
61
60
|
|
|
@@ -64,8 +63,9 @@ The values you set override the default values, they are not merged.
|
|
|
64
63
|
Be specific with `entry` files. Minimize the number of entry files and wildcards
|
|
65
64
|
for better results.
|
|
66
65
|
|
|
67
|
-
Plugins are enabled automatically, and
|
|
68
|
-
Next.js, Astro, Remix, Vitest, Playwright and many
|
|
66
|
+
Plugins are enabled automatically, and their entry files are added
|
|
67
|
+
automatically. Such as for Next.js, Astro, Remix, Vitest, Playwright and many
|
|
68
|
+
more.
|
|
69
69
|
|
|
70
70
|
:::
|
|
71
71
|
|
|
@@ -198,17 +198,23 @@ Exit with non-zero code (1) if there are any configuration hints.
|
|
|
198
198
|
|
|
199
199
|
:::tip
|
|
200
200
|
|
|
201
|
-
Please read [configuring project files][9] before using the `ignore` option
|
|
202
|
-
because in most cases you'll want to fine‑tune `entry` and `project` (or use
|
|
203
|
-
production mode) instead.
|
|
201
|
+
Please read [configuring project files][9] before using the `ignore` option.
|
|
204
202
|
|
|
205
203
|
:::
|
|
206
204
|
|
|
207
|
-
|
|
205
|
+
Avoid `ignore` patterns. There is almost always a better solution:
|
|
206
|
+
|
|
207
|
+
- Follow up on configuration hints (if there are any).
|
|
208
|
+
- Fine-tune `entry` and `project` patterns.
|
|
209
|
+
- Use [production mode][10].
|
|
210
|
+
- Other `ignore*` options.
|
|
211
|
+
|
|
212
|
+
**NOTE**: An exception to the rule: to _temporarily_ report only issues in files
|
|
213
|
+
that match the negated `ignore` pattern:
|
|
208
214
|
|
|
209
215
|
```json title="knip.json"
|
|
210
216
|
{
|
|
211
|
-
"ignore": ["src/
|
|
217
|
+
"ignore": ["!src/dir/**"]
|
|
212
218
|
}
|
|
213
219
|
```
|
|
214
220
|
|
|
@@ -271,6 +277,8 @@ export default {
|
|
|
271
277
|
|
|
272
278
|
Suffix an item with `!` to enable it only in production mode.
|
|
273
279
|
|
|
280
|
+
Also see [Unused dependencies][11].
|
|
281
|
+
|
|
274
282
|
### `ignoreMembers`
|
|
275
283
|
|
|
276
284
|
Array of class and enum members to exclude from the report. Regular expressions
|
|
@@ -399,7 +407,7 @@ files (`.js` or `.ts`), not in JSON configuration files.
|
|
|
399
407
|
|
|
400
408
|
Override built-in compilers or add custom compilers for additional file types.
|
|
401
409
|
|
|
402
|
-
Also see [Compilers][
|
|
410
|
+
Also see [Compilers][12].
|
|
403
411
|
|
|
404
412
|
[1]: ../reference/dynamic-configuration.mdx
|
|
405
413
|
[2]: ../overview/configuration.md
|
|
@@ -410,4 +418,6 @@ Also see [Compilers][10].
|
|
|
410
418
|
[7]: ../features/rules-and-filters.md#filters
|
|
411
419
|
[8]: ./jsdoc-tsdoc-tags.md
|
|
412
420
|
[9]: ../guides/configuring-project-files.md
|
|
413
|
-
[10]: ../features/
|
|
421
|
+
[10]: ../features/production-mode.md
|
|
422
|
+
[11]: ../guides/handling-issues.mdx#unused-dependencies
|
|
423
|
+
[12]: ../features/compilers.md
|
|
@@ -2,31 +2,45 @@
|
|
|
2
2
|
title: Known Issues
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
List of known issues and workarounds for exceptions thrown during a Knip run.
|
|
6
|
+
|
|
7
|
+
See [handling issues][1] to learn more about dealing with lint issues.
|
|
6
8
|
|
|
7
9
|
## Exceptions from config files
|
|
8
10
|
|
|
9
11
|
An exception may be thrown when a Knip plugin loads a JavaScript or TypeScript
|
|
10
|
-
configuration file such as `webpack.config.js` or `vite.config.ts
|
|
11
|
-
load such files differently, in a different environment, or without certain
|
|
12
|
-
environment variables set.
|
|
12
|
+
configuration file such as `webpack.config.js` or `vite.config.ts`:
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
```sh
|
|
15
|
+
$ knip
|
|
16
|
+
Error loading .../vite.config.ts
|
|
17
|
+
```
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
Knip may load such files differently, in a different environment, with missing
|
|
20
|
+
environment variables, etcetera. Use `--debug` to locate the cause of the issue
|
|
21
|
+
with more details.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Potential workarounds:
|
|
24
|
+
|
|
25
|
+
- Disable loading the file by overriding the default `config` for that plugin.
|
|
26
|
+
- Example: `vite: { config: [] }`
|
|
27
|
+
- In a monorepo, be more specific like so:
|
|
28
|
+
`workspaces: { "packages/lib": { vite: { config: [] } } }`
|
|
29
|
+
- If this helps, add the file as an `entry` file for static analysis.
|
|
30
|
+
- Disable the related plugin.
|
|
31
|
+
- Example: `eslint: false`
|
|
32
|
+
- In a monorepo, be more specific like so:
|
|
33
|
+
`workspaces: { "packages/lib": { eslint: false } }`
|
|
34
|
+
- If this helps, add the file as an `entry` file for static analysis.
|
|
35
|
+
- As a last resort, ignore the workspace: `ignoreWorkspaces: ["packages/lib"]`.
|
|
23
36
|
|
|
24
37
|
## Path aliases in config files
|
|
25
38
|
|
|
26
39
|
Loading the configuration file (e.g. `cypress.config.ts`) for one of Knip's
|
|
27
40
|
plugins may give an error:
|
|
28
41
|
|
|
29
|
-
```
|
|
42
|
+
```sh
|
|
43
|
+
$ knip
|
|
30
44
|
Analyzing workspace ....
|
|
31
45
|
Error loading .../cypress.config.ts
|
|
32
46
|
Reason: Cannot find module '@alias/name'
|
|
@@ -35,15 +49,13 @@ Require stack:
|
|
|
35
49
|
```
|
|
36
50
|
|
|
37
51
|
Some tools (such as Cypress and Jest) support using TypeScript path aliases in
|
|
38
|
-
the configuration file.
|
|
39
|
-
compared to `tsconfig.json#compilerOptions.paths` and `knip.json#paths` (e.g.
|
|
40
|
-
the target values are not arrays).
|
|
52
|
+
the configuration file.
|
|
41
53
|
|
|
42
54
|
Potential workarounds:
|
|
43
55
|
|
|
44
56
|
- Rewrite the import in the configuration file to a relative import.
|
|
45
57
|
- Use Bun with [knip-bun][2].
|
|
46
|
-
- [
|
|
58
|
+
- See [exceptions from config files][3] for more potential workarounds.
|
|
47
59
|
|
|
48
60
|
## Nx Daemon
|
|
49
61
|
|
|
@@ -53,12 +65,13 @@ In Nx projects you might encounter this error:
|
|
|
53
65
|
NX Daemon process terminated and closed the connection
|
|
54
66
|
```
|
|
55
67
|
|
|
56
|
-
The solution is to [disable the Nx Daemon][
|
|
68
|
+
The solution is to [disable the Nx Daemon][4]:
|
|
57
69
|
|
|
58
70
|
```sh
|
|
59
71
|
NX_DAEMON=false knip
|
|
60
72
|
```
|
|
61
73
|
|
|
62
|
-
[1]:
|
|
74
|
+
[1]: ../guides/handling-issues.mdx
|
|
63
75
|
[2]: ./cli.md#knip-bun
|
|
64
|
-
[3]:
|
|
76
|
+
[3]: #exceptions-from-config-files
|
|
77
|
+
[4]: https://nx.dev/concepts/nx-daemon#turning-it-off
|
|
@@ -8,26 +8,6 @@ sidebar:
|
|
|
8
8
|
|
|
9
9
|
This plugin is enabled if `"bun"` is listed in `"dependencies"` or `"devDependencies"` in `package.json`.
|
|
10
10
|
|
|
11
|
-
## Default configuration
|
|
12
|
-
|
|
13
|
-
If this plugin is enabled, the following configuration is added automatically:
|
|
14
|
-
|
|
15
|
-
```json
|
|
16
|
-
{
|
|
17
|
-
"bun": {
|
|
18
|
-
"config": [
|
|
19
|
-
"package.json"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Depending on local configuration, plugins may modify the defaults as shown.
|
|
26
|
-
|
|
27
|
-
Custom `config` or `entry` options override default values, they are not merged.
|
|
28
|
-
|
|
29
|
-
See [Plugins](../../explanations/plugins) for more details about plugins and their `entry` and `config` options.
|
|
30
|
-
|
|
31
11
|
## Generated from source
|
|
32
12
|
|
|
33
13
|
This page was generated from the [bun plugin source code](https://github.com/webpro-nl/knip/blob/main/packages/knip/src/plugins/bun/index.ts).
|
|
@@ -23,10 +23,10 @@ If this plugin is enabled, the following configuration is added automatically:
|
|
|
23
23
|
"lefthook": {
|
|
24
24
|
"config": [
|
|
25
25
|
"lefthook.yml",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
26
|
+
"../../../../../.git/hooks/prepare-commit-msg",
|
|
27
|
+
"../../../../../.git/hooks/commit-msg",
|
|
28
|
+
"../../../../../.git/hooks/pre-{applypatch,commit,merge-commit,push,rebase,receive}",
|
|
29
|
+
"../../../../../.git/hooks/post-{checkout,commit,merge,rewrite}"
|
|
30
30
|
]
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -39,7 +39,7 @@ See [Plugins](../../explanations/plugins) for more details about plugins and the
|
|
|
39
39
|
|
|
40
40
|
## Note
|
|
41
41
|
|
|
42
|
-
Also see [integrated monorepos](/features/integrated-monorepos).
|
|
42
|
+
Also see [integrated monorepos](/features/integrated-monorepos) and the note regarding internal workspace dependencies.
|
|
43
43
|
|
|
44
44
|
## Shell commands
|
|
45
45
|
|
|
@@ -18,11 +18,11 @@ If this plugin is enabled, the following configuration is added automatically:
|
|
|
18
18
|
{
|
|
19
19
|
"playwright-ct": {
|
|
20
20
|
"config": [
|
|
21
|
-
"playwright-ct.config.{js,ts}"
|
|
22
|
-
"playwright/index.{js,ts,jsx,tsx}"
|
|
21
|
+
"playwright-ct.config.{js,ts}"
|
|
23
22
|
],
|
|
24
23
|
"entry": [
|
|
25
|
-
"**/*.@(spec|test).?(c|m)[jt]s?(x)"
|
|
24
|
+
"**/*.@(spec|test).?(c|m)[jt]s?(x)",
|
|
25
|
+
"playwright/index.{js,ts,jsx,tsx}"
|
|
26
26
|
]
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: VitePress
|
|
3
|
+
sidebar:
|
|
4
|
+
hidden: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Enabled
|
|
8
|
+
|
|
9
|
+
This plugin is enabled if `"vitepress"` is listed in `"dependencies"` or `"devDependencies"` in `package.json`.
|
|
10
|
+
|
|
11
|
+
## Default configuration
|
|
12
|
+
|
|
13
|
+
If this plugin is enabled, the following configuration is added automatically:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"vitepress": {
|
|
18
|
+
"entry": [
|
|
19
|
+
".vitepress/config.{js,ts,mjs,mts}",
|
|
20
|
+
".vitepress/theme/index.{js,ts,mjs,mts}"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Depending on local configuration, plugins may modify the defaults as shown.
|
|
27
|
+
|
|
28
|
+
Custom `config` or `entry` options override default values, they are not merged.
|
|
29
|
+
|
|
30
|
+
See [Plugins](../../explanations/plugins) for more details about plugins and their `entry` and `config` options.
|
|
31
|
+
|
|
32
|
+
## Generated from source
|
|
33
|
+
|
|
34
|
+
This page was generated from the [vitepress plugin source code](https://github.com/webpro-nl/knip/blob/main/packages/knip/src/plugins/vitepress/index.ts).
|
|
@@ -8,7 +8,6 @@ import Posts from '../../components/Posts.astro';
|
|
|
8
8
|
import Projects from '../../components/Projects.astro';
|
|
9
9
|
import SponsorsComponent from '../../components/Sponsors.astro';
|
|
10
10
|
import SponsorsChart from '../../components/SponsorsChart.astro';
|
|
11
|
-
import SponsorsPast from '../../components/SponsorsPast.astro';
|
|
12
11
|
|
|
13
12
|
:::article{.prose}
|
|
14
13
|
|
|
@@ -41,7 +40,7 @@ one year before that.
|
|
|
41
40
|
<SponsorsChart />
|
|
42
41
|
|
|
43
42
|
- The monthly aggregated average over the charted period is $514.
|
|
44
|
-
- The monthly recurring average without one-time payments is $
|
|
43
|
+
- The monthly recurring average without one-time payments is $345.
|
|
45
44
|
- GitHub Sponsors is for my GitHub account. This has more repositories, but in
|
|
46
45
|
practice targets mostly Knip (and perhaps some [release-it][5]).
|
|
47
46
|
- [Chart generated][6] using [Venz][7].
|
|
@@ -61,5 +60,5 @@ one year before that.
|
|
|
61
60
|
[3]: https://github.com/sponsors/webpro
|
|
62
61
|
[4]: https://opencollective.com/knip
|
|
63
62
|
[5]: https://github.com/release-it/release-it
|
|
64
|
-
[6]: https://try.venz.dev?type=pivot&lp=tr&br=0&labelX=month&labelY=amount+\($\)&l=GitHub+Sponsors&color=%23fbfbfb&l=Open+Collective&color=%232487ff&label=2023-11&data=9,0&label=2023-12&data=74,0&label=2024-01&data=239,0&label=2024-02&data=489,0&label=2024-03&data=189,0&label=2024-04&data=204,750&label=2024-05&data=304,101&label=2024-06&data=1204,0&label=2024-07&data=204,35&label=2024-08&data=229,25&label=2024-09&data=2729,25&label=2024-10&data=410,45&label=2024-11&data=222,45&label=2024-12&data=222,145&label=2025-01&data=342,145&label=2025-02&data=244,145&label=2025-03&data=222,145&label=2025-04&data=222,145&label=2025-05&data=242,145&label=2025-06&data=247,145&label=2025-07&data=297,145&label=2025-08&data=268,145&label=2025-09&data=350,145&label=2025-10&data=375,145
|
|
63
|
+
[6]: https://try.venz.dev?type=pivot&lp=tr&br=0&labelX=month&labelY=amount+\($\)&l=GitHub+Sponsors&color=%23fbfbfb&l=Open+Collective&color=%232487ff&label=2023-11&data=9,0&label=2023-12&data=74,0&label=2024-01&data=239,0&label=2024-02&data=489,0&label=2024-03&data=189,0&label=2024-04&data=204,750&label=2024-05&data=304,101&label=2024-06&data=1204,0&label=2024-07&data=204,35&label=2024-08&data=229,25&label=2024-09&data=2729,25&label=2024-10&data=410,45&label=2024-11&data=222,45&label=2024-12&data=222,145&label=2025-01&data=342,145&label=2025-02&data=244,145&label=2025-03&data=222,145&label=2025-04&data=222,145&label=2025-05&data=242,145&label=2025-06&data=247,145&label=2025-07&data=297,145&label=2025-08&data=268,145&label=2025-09&data=350,145&label=2025-10&data=375,145&label=2025-11&data=549,145&label=2025-12&data=355,145
|
|
65
64
|
[7]: https://try.venz.dev
|
package/src/texts.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { CURATED_RESOURCES } from './curated-resources.js';
|
|
2
2
|
|
|
3
3
|
export const WORKFLOW = `Workflow:
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
1. Read essential documentation resources:
|
|
6
|
+
- configuring-project-files (must read to configure entry patterns)
|
|
7
|
+
- plugins-explanation (understand entries added by auto-detected plugins)
|
|
8
|
+
- handling-issues (comprehensive guide to deal with any reported issue type)
|
|
9
|
+
- configuration-reference (all knip.json configuration options)
|
|
5
10
|
2. Run analysis (knip-run) to get configuration hints and issues
|
|
6
11
|
3. Address the hints by adjusting knip.json
|
|
7
|
-
4. Repeat steps 2-3 until
|
|
8
|
-
|
|
9
|
-
Essential resources:
|
|
10
|
-
- configuring-project-files (must read to configure entry patterns)
|
|
11
|
-
- plugins-explanation (understand entries added by auto-detected plugins)
|
|
12
|
-
- handling-issues (comprehensive guide to deal with any reported issue type)
|
|
13
|
-
- configuration-reference (all knip.json configuration options)
|
|
12
|
+
4. Repeat steps 2-3 until hints are gone and false positives are minimized
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- Before suggesting fixes/solutions,
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- Knip does not
|
|
14
|
+
Important notes:
|
|
15
|
+
- For prompts like "run knip" or "clean up codebase" or "no more slop": always run workflow to configure Knip first.
|
|
16
|
+
- If you hit errors (not lint issues), consult: known-issues
|
|
17
|
+
- Before suggesting fixes/solutions, consult: handling-issues and reference/jsdoc-tsdoc-tags
|
|
18
|
+
- For cleanup, consult: features/auto-fix
|
|
19
|
+
- To install Knip and start using it from CLI, consult: getting-started and reference/cli
|
|
20
|
+
- Knip does not remove unused imports/variables inside files (use a linter)
|
|
22
21
|
`;
|
|
23
22
|
|
|
24
23
|
// pkg.contributes.languageModelTools[0].modelDescription
|
|
@@ -44,26 +43,17 @@ ${Object.entries(CURATED_RESOURCES)
|
|
|
44
43
|
.map(([id, doc]) => `- ${id}: ${doc.description}`)
|
|
45
44
|
.join('\n')}
|
|
46
45
|
|
|
47
|
-
Can also fetch any doc by path (e.g
|
|
48
|
-
Use this instead of fetching from knip.dev.`;
|
|
46
|
+
Can also fetch any doc by path (e.g. "reference/cli" or "guides/troubleshooting").
|
|
47
|
+
Use this instead of fetching from https://knip.dev.`;
|
|
49
48
|
|
|
50
49
|
// pkg.contributes.languageModelTools[1].inputSchema.properties.topic.description
|
|
51
50
|
export const DOC_TOOL_TOPIC_DESCRIPTION =
|
|
52
51
|
'Topic key (e.g. "configuring-project-files") for curated resources, or path (e.g. "explanations/plugins") for all available docs';
|
|
53
52
|
|
|
54
53
|
export const ERROR_HINT = `For unexpected errors (exit code 2) such as "error loading file":
|
|
54
|
+
|
|
55
55
|
- Consult docs: known-issues and configuration-reference
|
|
56
|
-
- If no config file exists, create knip.json in root
|
|
57
|
-
- Damage control for "error loading file":
|
|
58
|
-
1) First try to disable the related plugin's config file:
|
|
59
|
-
- E.g. vite: { config: [] }
|
|
60
|
-
- In a monorepo use e.g. { workspaces: { "packages/lib": { vite: { config: [] } } } }
|
|
61
|
-
- If this succeeds, add the file as a regular entry point
|
|
62
|
-
2) Then try to disable the related plugin:
|
|
63
|
-
- E.g. vite: false
|
|
64
|
-
- In a monorepo use e.g. { workspaces: { "packages/lib": { vite: false } } }
|
|
65
|
-
- If this succeeds, add the file as a regular entry point
|
|
66
|
-
3) As a last resort, ignore the workspace: ignoreWorkspaces: ["packages/lib"]
|
|
56
|
+
- If no config file exists, create knip.json in the project root
|
|
67
57
|
- Run knip again`;
|
|
68
58
|
|
|
69
59
|
export const CONFIG_REVIEW_HINT = `Review the existing configuration for potential improvements:
|
|
@@ -71,7 +61,7 @@ export const CONFIG_REVIEW_HINT = `Review the existing configuration for potenti
|
|
|
71
61
|
- Never use "ignore" patterns (hides real issues!), always prefer specific solutions, other ignore* options are allowed
|
|
72
62
|
- Many unused exported types? Add: ignoreExportsUsedInFile: { interface: true, type: true } (prefer this over other ignore* options)
|
|
73
63
|
- Remove ignore patterns that don't match any files
|
|
74
|
-
-
|
|
64
|
+
- Remove redundant ignore patterns: Knip respects .gitignore (node_modules, dist, build, .git)
|
|
75
65
|
- Remove entry patterns covered by config defaults and auto-detected plugins
|
|
76
66
|
- Config files (e.g. vite.config.ts) showing as unused? Enable/disable the plugin explicitly
|
|
77
67
|
- Dependencies matching Node.js builtins: add to ignoreDependencies (e.g. buffer, process)
|