@knip/mcp 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/docs/docs/blog/brief-history.md +1 -1
- package/src/docs/docs/blog/for-editors-and-agents.md +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/blog/knip-v5.mdx +1 -1
- package/src/docs/docs/blog/knip-v6.md +145 -0
- package/src/docs/docs/blog/release-notes-v2.md +1 -1
- package/src/docs/docs/blog/slim-down-to-speed-up.md +1 -1
- package/src/docs/docs/blog/state-of-knip.md +1 -1
- package/src/docs/docs/blog/two-years.mdx +1 -1
- package/src/docs/docs/explanations/comparison-and-migration.md +2 -2
- package/src/docs/docs/features/auto-fix.mdx +3 -33
- package/src/docs/docs/features/reporters.md +16 -13
- package/src/docs/docs/features/rules-and-filters.md +1 -1
- package/src/docs/docs/guides/handling-issues.mdx +32 -48
- package/src/docs/docs/guides/performance.md +7 -62
- package/src/docs/docs/index.mdx +3 -3
- package/src/docs/docs/overview/configuration.md +1 -1
- package/src/docs/docs/overview/getting-started.mdx +1 -1
- package/src/docs/docs/reference/cli.md +31 -56
- package/src/docs/docs/reference/configuration.md +7 -7
- package/src/docs/docs/reference/faq.md +48 -63
- package/src/docs/docs/reference/issue-types.md +17 -17
- package/src/docs/docs/typescript/unused-exports.md +7 -8
- package/src/docs/docs/writing-a-plugin/index.md +14 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knip/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Knip MCP Server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"knip",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
30
30
|
"zod": "^4.1.11",
|
|
31
|
-
"knip": "^
|
|
31
|
+
"knip": "^6.0.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
34
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"release": "release-it -c ../../.release-it.json"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Announcing Knip v6
|
|
3
|
+
date: 2026-03-20
|
|
4
|
+
sidebar:
|
|
5
|
+
order: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
_Published: 2026-03-20_
|
|
9
|
+
|
|
10
|
+
## Knip v6 is out!
|
|
11
|
+
|
|
12
|
+
This release is all about replacing the TypeScript backend entirely with
|
|
13
|
+
`oxc-parser` and `oxc-resolver`, and making Knip a whole lot faster!
|
|
14
|
+
|
|
15
|
+
## From TypeScript to oxc
|
|
16
|
+
|
|
17
|
+
Two years ago, the ["slim down to speed up"][1] and [Knip v4][2] work removed a
|
|
18
|
+
lot of overhead around TypeScript programs, made serialization and caching
|
|
19
|
+
practical, and improved memory efficiency a lot. But there was still a ceiling:
|
|
20
|
+
parsing and module resolution still depended on TypeScript APIs designed for
|
|
21
|
+
IDEs and language servers — not for the kind of single-pass static analysis Knip
|
|
22
|
+
does.
|
|
23
|
+
|
|
24
|
+
Starting today, Knip v6 parses your source files with [oxc-parser][3]. This is
|
|
25
|
+
more than just a parser swap for the sake of using the latest 'n greatest.
|
|
26
|
+
|
|
27
|
+
Knip has always been designed to parse each file only once, but the TypeScript
|
|
28
|
+
backend carried the overhead of wiring up an entire program along with the
|
|
29
|
+
typechecker. That's useful for IDEs keeping symbols connected, but much less so
|
|
30
|
+
when you only need to traverse an AST once to collect imports and exports.
|
|
31
|
+
The TypeScript backend made the setup as a whole harder and slower than it
|
|
32
|
+
needed to be, especially to keep large monorepos in check.
|
|
33
|
+
|
|
34
|
+
Now with TypeScript itself Go-ing places, replacing that backend was only a
|
|
35
|
+
matter of time.
|
|
36
|
+
|
|
37
|
+
Unsurprisingly, the search didn't take long: `oxc-parser` offers everything we
|
|
38
|
+
need and its (experimental) raw transfer is crazy fast. Massive props to
|
|
39
|
+
[overlookmotel][4], [Boshen][5] and all contributors for all the work on
|
|
40
|
+
[the oxc suite][6]!
|
|
41
|
+
|
|
42
|
+
## Performance tuning
|
|
43
|
+
|
|
44
|
+
Next to this major refactor, I've been having a ball tuning Knip's performance
|
|
45
|
+
further. One thing to highlight here is that a few more plugins have been
|
|
46
|
+
refactored to statically analyze configuration files directly, as opposed to
|
|
47
|
+
actually importing them (including transitive dependencies...). This includes
|
|
48
|
+
the ESLint ("flat config"), tsdown and tsup plugins.
|
|
49
|
+
|
|
50
|
+
## The numbers
|
|
51
|
+
|
|
52
|
+
Comparing v5 and v6 in some projects using Knip, all boosts are in the **2-4x** range:
|
|
53
|
+
|
|
54
|
+
[![venz-chart][8]][7]
|
|
55
|
+
|
|
56
|
+
Trust me, I could look at this chart all day long! The same numbers in a table:
|
|
57
|
+
|
|
58
|
+
| Project | v5.88.0 | v6.0.0 |
|
|
59
|
+
| ---------------- | ------: | -----: |
|
|
60
|
+
| [astro][9] | 4.0s | 2.0s |
|
|
61
|
+
| [query][10] | 3.8s | 1.7s |
|
|
62
|
+
| [rolldown][11] | 3.7s | 1.7s |
|
|
63
|
+
| [sentry][12] | 11.0s | 4.0s |
|
|
64
|
+
| [TypeScript][13] | 3.7s | 0.9s |
|
|
65
|
+
|
|
66
|
+
## What's new
|
|
67
|
+
|
|
68
|
+
- Did I already mention Knip got 2-4x faster?
|
|
69
|
+
- Support for TS namespaces (and modules), new issue type `namespaceMembers`:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
export namespace MyNamespace {
|
|
73
|
+
export const myName = 'knip'; // we were ignored in v5,
|
|
74
|
+
export type MyType = string; // yet in v6 we are included
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Breaking changes
|
|
79
|
+
|
|
80
|
+
Granted, most of you won't even notice. Here's the list:
|
|
81
|
+
|
|
82
|
+
- Dropped support for Node.js v18 → Knip v6 requires Node.js v20.19.0 or newer
|
|
83
|
+
- Dropped issue type `classMembers`
|
|
84
|
+
- Dropped `--include-libs` → this is now the default and only behavior
|
|
85
|
+
- Dropped `--isolate-workspaces` → this is now the default and only behavior
|
|
86
|
+
- Dropped `--experimental-tags` → use [`--tags`][14]
|
|
87
|
+
- In [reporter functions][15], `issues.files` is consistent with other issue shapes. Removed `issues._files`.
|
|
88
|
+
- In the [JSON reporter][16], issues are consistently arrays for any issue type. Removed root `files`.
|
|
89
|
+
|
|
90
|
+
## Editor Extensions
|
|
91
|
+
|
|
92
|
+
[Editor extensions][17] benefit from the core upgrades, for being faster and more
|
|
93
|
+
memory-efficient. Regardless of new extension releases, the local version of
|
|
94
|
+
Knip will be detected and used. Upgrade `knip` in your dependencies when you're
|
|
95
|
+
ready.
|
|
96
|
+
|
|
97
|
+
## What about classMembers?
|
|
98
|
+
|
|
99
|
+
I feel you. Even Knip itself was using it. Until today.
|
|
100
|
+
|
|
101
|
+
The problem is that the implementation relies on the JS-based `ts.LanguageService`
|
|
102
|
+
API that exposes the `findReferences` method. TypeScript v6 is the last JS-based
|
|
103
|
+
release, and TypeScript v7 is a full rewrite in Go. I am left wondering if it
|
|
104
|
+
ever will be feasible and practical to build such features using primitives
|
|
105
|
+
(i.e. not via LSP) in a JS-based CLI (references: [microsoft/typescript-go#455][18],
|
|
106
|
+
[@typescript/api][19]). Knip was already pretty unique for even trying this in
|
|
107
|
+
a CLI tool.
|
|
108
|
+
|
|
109
|
+
Not that many projects seem to be using it either:
|
|
110
|
+
[github.com search for "classMembers path\:knip.json"][20].
|
|
111
|
+
|
|
112
|
+
If your project relies on it, feel free to open an issue on GitHub or contact me
|
|
113
|
+
and maybe we can work something out. Maybe a separate dedicated tool could work,
|
|
114
|
+
or extended support for Knip v5.
|
|
115
|
+
|
|
116
|
+
## Upgrade today
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
npm install -D knip@latest
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Deep closing thoughts...
|
|
123
|
+
|
|
124
|
+
Remember, Knip it before you ship it! Have a great day ☀️
|
|
125
|
+
|
|
126
|
+
[1]: ./slim-down-to-speed-up.md
|
|
127
|
+
[2]: ./knip-v4.mdx
|
|
128
|
+
[3]: https://oxc.rs/docs/guide/usage/parser
|
|
129
|
+
[4]: https://github.com/overlookmotel
|
|
130
|
+
[5]: https://github.com/Boshen
|
|
131
|
+
[6]: https://oxc.rs
|
|
132
|
+
[7]: https://try.venz.dev/?type=bar&labelX=Knip&labelY=duration+(s)&label=astro&label=query&label=rolldown&label=sentry&label=typescript&l=v5.88.0&l=v6.0.0&data=4*2&data=3.8*1.7&data=3.7*1.7&data=11*4&data=3.7*0.9
|
|
133
|
+
[8]: https://cdn.venz.dev/i/chart.svg?pad=0&type=bar&labelX=Knip&labelY=duration+(s)&label=astro&label=query&label=rolldown&label=sentry&label=typescript&l=v5.88.0&l=v6.0.0&data=4*2&data=3.8*1.7&data=3.7*1.7&data=11*4&data=3.7*0.9&theme=dark
|
|
134
|
+
[9]: https://github.com/withastro/astro
|
|
135
|
+
[10]: https://github.com/TanStack/query
|
|
136
|
+
[11]: https://github.com/rolldown/rolldown
|
|
137
|
+
[12]: https://github.com/getsentry/sentry
|
|
138
|
+
[13]: https://github.com/microsoft/TypeScript
|
|
139
|
+
[14]: ../reference/configuration.md#tags
|
|
140
|
+
[15]: ../features/reporters.md#custom-reporters
|
|
141
|
+
[16]: ../features/reporters.md#json
|
|
142
|
+
[17]: ../reference/integrations.md
|
|
143
|
+
[18]: https://github.com/microsoft/typescript-go/discussions/455
|
|
144
|
+
[19]: https://github.com/microsoft/typescript-go/tree/main/_packages/api
|
|
145
|
+
[20]: https://github.com/search?q=classMembers%20path%3Aknip.json&type=code
|
|
@@ -71,7 +71,7 @@ ts-prune
|
|
|
71
71
|
knip --include exports,types,nsExports,nsTypes
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
Use `knip --exports` to also include
|
|
74
|
+
Use `knip --exports` to also include enum and namespace members.
|
|
75
75
|
|
|
76
76
|
**Project status**: The project is archived and recommends Knip.
|
|
77
77
|
|
|
@@ -87,7 +87,7 @@ ts-unused-exports
|
|
|
87
87
|
knip --include exports,types,nsExports,nsTypes
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Use `knip --exports` to also include
|
|
90
|
+
Use `knip --exports` to also include enum and namespace members.
|
|
91
91
|
|
|
92
92
|
### tsr
|
|
93
93
|
|
|
@@ -11,8 +11,7 @@ following [issue types][1]:
|
|
|
11
11
|
|
|
12
12
|
- Remove `export` keyword for unused exports, re-exports, and exported types
|
|
13
13
|
- Remove `export default` keywords for unused default exports
|
|
14
|
-
- Remove unused enum members
|
|
15
|
-
- Remove unused class members (disabled by default)
|
|
14
|
+
- Remove unused enum and namespace members
|
|
16
15
|
- Remove unused `dependencies` and `devDependencies` from `package.json`
|
|
17
16
|
- Remove unused files
|
|
18
17
|
- Remove unused catalog entries
|
|
@@ -288,37 +287,9 @@ Unused dependencies are removed from `package.json`:
|
|
|
288
287
|
}
|
|
289
288
|
```
|
|
290
289
|
|
|
291
|
-
### Class members <Badge text="experimental" variant="caution" />
|
|
292
|
-
|
|
293
|
-
Unused members of classes can be removed:
|
|
294
|
-
|
|
295
|
-
```diff title="file.ts"
|
|
296
|
-
export class Rectangle {
|
|
297
|
-
constructor(public width: number, public height: number) {}
|
|
298
|
-
|
|
299
|
-
- static Key = 1;
|
|
300
|
-
+
|
|
301
|
-
|
|
302
|
-
area() {
|
|
303
|
-
return this.width * this.height;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
- public get unusedGetter(): string {
|
|
307
|
-
- return 'unusedGetter';
|
|
308
|
-
- }
|
|
309
|
-
}
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Currently Knip might be too eager removing class members when they're not
|
|
313
|
-
referenced internally but meant to be called by an external library. For
|
|
314
|
-
instance, Knip might think `componentDidMount` and `render` in React class
|
|
315
|
-
component are unused and will remove those.
|
|
316
|
-
|
|
317
|
-
Note that [`classMembers` aren't included by default][4].
|
|
318
|
-
|
|
319
290
|
### Catalog entries
|
|
320
291
|
|
|
321
|
-
Unused [catalog][
|
|
292
|
+
Unused [catalog][4] entries are removed from `pnpm-workspace.yaml`:
|
|
322
293
|
|
|
323
294
|
```diff title="pnpm-workspace.yaml"
|
|
324
295
|
packages:
|
|
@@ -344,5 +315,4 @@ Operations that auto-fix does not (yet) perform and why:
|
|
|
344
315
|
[1]: ../reference/issue-types.md
|
|
345
316
|
[2]: https://github.com/JoshuaKGoldberg/formatly
|
|
346
317
|
[3]: https://github.com/webpro-nl/remove-unused-vars
|
|
347
|
-
[4]:
|
|
348
|
-
[5]: https://pnpm.io/catalogs
|
|
318
|
+
[4]: https://pnpm.io/catalogs
|
|
@@ -29,7 +29,6 @@ object per file structured like this:
|
|
|
29
29
|
|
|
30
30
|
```json
|
|
31
31
|
{
|
|
32
|
-
"files": ["src/unused.ts"],
|
|
33
32
|
"issues": [
|
|
34
33
|
{
|
|
35
34
|
"file": "package.json",
|
|
@@ -55,18 +54,22 @@ object per file structured like this:
|
|
|
55
54
|
{ "name": "unusedEnum", "line": 3, "col": 13, "pos": 71 },
|
|
56
55
|
{ "name": "unusedType", "line": 8, "col": 14, "pos": 145 }
|
|
57
56
|
],
|
|
58
|
-
"enumMembers":
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
"enumMembers": [
|
|
58
|
+
{
|
|
59
|
+
"namespace": "MyEnum",
|
|
60
|
+
"name": "unusedMember",
|
|
61
|
+
"line": 13,
|
|
62
|
+
"col": 3,
|
|
63
|
+
"pos": 167
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"namespace": "MyEnum",
|
|
67
|
+
"name": "unusedKey",
|
|
68
|
+
"line": 15,
|
|
69
|
+
"col": 3,
|
|
70
|
+
"pos": 205
|
|
71
|
+
}
|
|
72
|
+
],
|
|
70
73
|
"duplicates": ["Registration", "default"]
|
|
71
74
|
}
|
|
72
75
|
]
|
|
@@ -52,6 +52,7 @@ Knip has shortcuts to include only specific issue types.
|
|
|
52
52
|
- `exports`
|
|
53
53
|
- `types`
|
|
54
54
|
- `enumMembers`
|
|
55
|
+
- `namespaceMembers`
|
|
55
56
|
- `duplicates`
|
|
56
57
|
|
|
57
58
|
3. The `--files` flag is a shortcut for `--include files`
|
|
@@ -73,7 +74,6 @@ Example:
|
|
|
73
74
|
{
|
|
74
75
|
"rules": {
|
|
75
76
|
"files": "warn",
|
|
76
|
-
"classMembers": "off",
|
|
77
77
|
"duplicates": "off"
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -517,7 +517,7 @@ option][39] to tell Knip where to find the icon types:
|
|
|
517
517
|
Where `[framework]` is the name of the framework you're using (see [available
|
|
518
518
|
types][42]).
|
|
519
519
|
|
|
520
|
-
**Solution**:
|
|
520
|
+
**Solution**: configure [paths][39].
|
|
521
521
|
|
|
522
522
|
## Unused exports
|
|
523
523
|
|
|
@@ -525,8 +525,8 @@ By default, Knip does not report unused exports of `entry` files.
|
|
|
525
525
|
|
|
526
526
|
The most common causes for unused exports include:
|
|
527
527
|
|
|
528
|
-
- [Namespace enumerations][
|
|
529
|
-
- [External libraries][
|
|
528
|
+
- [Namespace enumerations][43]
|
|
529
|
+
- [External libraries][44]
|
|
530
530
|
|
|
531
531
|
Use the `--exports` flag to [filter][17] and focus only on issues related to
|
|
532
532
|
exports:
|
|
@@ -535,7 +535,7 @@ exports:
|
|
|
535
535
|
knip --exports
|
|
536
536
|
```
|
|
537
537
|
|
|
538
|
-
Use [includeEntryExports][
|
|
538
|
+
Use [includeEntryExports][45] to report unused exports of entry files as well.
|
|
539
539
|
This can be set per workspace.
|
|
540
540
|
|
|
541
541
|
### Namespace enumerations
|
|
@@ -547,7 +547,7 @@ are then **not** reported.
|
|
|
547
547
|
**Solution**: if all exports on imported namespaces should be considered
|
|
548
548
|
individually, include the `nsExports` issue type to disable the heuristic.
|
|
549
549
|
|
|
550
|
-
See [namespace imports][
|
|
550
|
+
See [namespace imports][46] to see all related patterns.
|
|
551
551
|
|
|
552
552
|
### External libraries
|
|
553
553
|
|
|
@@ -578,27 +578,16 @@ non-standard consumption of your exports? Here's an example:
|
|
|
578
578
|
</Tabs>
|
|
579
579
|
|
|
580
580
|
Knip understands `Apple` is used, since it's standard usage. But `Orange` is
|
|
581
|
-
referenced through a function of an external library.
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
**Solution**: include the type definitions of external libraries with the
|
|
586
|
-
[--include-libs][43] flag:
|
|
587
|
-
|
|
588
|
-
```shell
|
|
589
|
-
knip --include-libs
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
This comes at a performance and memory penalty, but should give better results
|
|
593
|
-
if you need it. This flag is implied when [classMembers][48] are included (that
|
|
594
|
-
feature comes with roughly the same performance penalty).
|
|
581
|
+
referenced through a function of an external library. Knip includes external
|
|
582
|
+
type definitions to trace such usage, but in some cases it may not be able to
|
|
583
|
+
follow the reference through the library's API.
|
|
595
584
|
|
|
596
585
|
### Exclude exports from the report
|
|
597
586
|
|
|
598
587
|
To exclude false positives from the report, there are a few options:
|
|
599
588
|
|
|
600
|
-
- [Ignore exports used in file][
|
|
601
|
-
- Individual exports can be [tagged using JSDoc syntax][
|
|
589
|
+
- [Ignore exports used in file][47] for exports used internally.
|
|
590
|
+
- Individual exports can be [tagged using JSDoc syntax][48].
|
|
602
591
|
- Have the export in an entry file:
|
|
603
592
|
|
|
604
593
|
- Add the file to the `entry` file patterns array in the configuration.
|
|
@@ -609,50 +598,47 @@ To exclude false positives from the report, there are a few options:
|
|
|
609
598
|
### Missing unused exports?
|
|
610
599
|
|
|
611
600
|
Did you expect certain exports in the report, but are they missing? They might
|
|
612
|
-
be exported from an entry file. In that case, use [--include-entry-exports][
|
|
601
|
+
be exported from an entry file. In that case, use [--include-entry-exports][45]
|
|
613
602
|
to make Knip also report unused exports in entry files.
|
|
614
603
|
|
|
615
604
|
The exports of non-standard extensions like `.astro`, `.mdx`, `.vue` or
|
|
616
605
|
`.svelte` are not available by default. See [compilers][21] for more details on
|
|
617
606
|
how to include them.
|
|
618
607
|
|
|
619
|
-
###
|
|
608
|
+
### Enum members
|
|
620
609
|
|
|
621
|
-
Unused members of exported
|
|
622
|
-
|
|
610
|
+
Unused enums and unused members of exported enums are reported by default.
|
|
611
|
+
Reporting such members can be disabled:
|
|
623
612
|
|
|
624
613
|
```sh
|
|
625
|
-
knip --
|
|
614
|
+
knip --exclude enumMembers
|
|
626
615
|
```
|
|
627
616
|
|
|
628
|
-
|
|
629
|
-
feature comes at a cost: linting will take more time and more memory.
|
|
630
|
-
|
|
631
|
-
Individual class members can be [tagged using JSDoc syntax][50].
|
|
617
|
+
Individual enum members can be [tagged using JSDoc syntax][48].
|
|
632
618
|
|
|
633
|
-
|
|
634
|
-
[--include-entry-exports][
|
|
619
|
+
Enums exported from entry files are ignored, and so are their members. Use
|
|
620
|
+
[--include-entry-exports][45] to make Knip also report members of unused exports
|
|
635
621
|
in entry files.
|
|
636
622
|
|
|
637
|
-
###
|
|
623
|
+
### Namespace members
|
|
638
624
|
|
|
639
|
-
Unused
|
|
625
|
+
Unused members of exported TypeScript namespaces are reported by default.
|
|
640
626
|
Reporting such members can be disabled:
|
|
641
627
|
|
|
642
628
|
```sh
|
|
643
|
-
knip --exclude
|
|
629
|
+
knip --exclude namespaceMembers
|
|
644
630
|
```
|
|
645
631
|
|
|
646
|
-
Individual
|
|
632
|
+
Individual namespace members can be [tagged using JSDoc syntax][48].
|
|
647
633
|
|
|
648
|
-
|
|
649
|
-
[--include-entry-exports][
|
|
634
|
+
Namespaces exported from entry files are ignored, and so are their members. Use
|
|
635
|
+
[--include-entry-exports][45] to make Knip also report members of unused exports
|
|
650
636
|
in entry files.
|
|
651
637
|
|
|
652
638
|
## Feedback or false positives?
|
|
653
639
|
|
|
654
640
|
If you believe Knip incorrectly reports something as unused (i.e. there's a
|
|
655
|
-
false positive), feel free to create a [minimal reproduction][
|
|
641
|
+
false positive), feel free to create a [minimal reproduction][49] and open an
|
|
656
642
|
issue on GitHub. It'll make Knip better for everyone!
|
|
657
643
|
|
|
658
644
|
[1]: #unused-files
|
|
@@ -697,12 +683,10 @@ issue on GitHub. It'll make Knip better for everyone!
|
|
|
697
683
|
[40]: ../reference/configuration.md#ignoreunresolved
|
|
698
684
|
[41]: https://www.npmjs.com/package/unplugin-icons
|
|
699
685
|
[42]: https://github.com/unplugin/unplugin-icons/tree/main/types
|
|
700
|
-
[43]:
|
|
701
|
-
[44]: #
|
|
702
|
-
[45]: #
|
|
703
|
-
[46]: ../
|
|
704
|
-
[47]: ../
|
|
705
|
-
[48]:
|
|
706
|
-
[49]: ../
|
|
707
|
-
[50]: ../reference/jsdoc-tsdoc-tags.md
|
|
708
|
-
[51]: ../guides/issue-reproduction.md
|
|
686
|
+
[43]: #namespace-enumerations
|
|
687
|
+
[44]: #external-libraries
|
|
688
|
+
[45]: ../reference/configuration.md#includeentryexports
|
|
689
|
+
[46]: ../guides/namespace-imports.md
|
|
690
|
+
[47]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
691
|
+
[48]: ../reference/jsdoc-tsdoc-tags.md
|
|
692
|
+
[49]: ../guides/issue-reproduction.md
|
|
@@ -23,72 +23,19 @@ exclude files from the analysis.
|
|
|
23
23
|
Read [configuring project files][1] for details and examples. Improving
|
|
24
24
|
configuration may have a significant impact on performance.
|
|
25
25
|
|
|
26
|
-
## Workspace sharing
|
|
27
|
-
|
|
28
|
-
Knip shares files from separate workspaces if the configuration in
|
|
29
|
-
`tsconfig.json` allows this. This aims to reduce memory consumption and run
|
|
30
|
-
duration. Relevant compiler options include `baseUrl`, `paths` and
|
|
31
|
-
`moduleResolution`.
|
|
32
|
-
|
|
33
|
-
With the `--debug` flag you can see how many programs Knip uses. Look for
|
|
34
|
-
messages like this:
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
...
|
|
38
|
-
[*] Installed 2 programs for 29 workspaces
|
|
39
|
-
...
|
|
40
|
-
[*] Analyzing used resolved files [P1/1] (123)
|
|
41
|
-
...
|
|
42
|
-
[*] Analyzing used resolved files [P1/2] (8)
|
|
43
|
-
...
|
|
44
|
-
[*] Analyzing used resolved files [P2/1] (41)
|
|
45
|
-
...
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
The first number in `P1/1` is the number of the programs, the second number
|
|
49
|
-
indicates additional entry files were found so it does another round of analysis
|
|
50
|
-
on those files.
|
|
51
|
-
|
|
52
|
-
Use [--isolate-workspaces][2] to disable this behavior. This is usually not
|
|
53
|
-
necessary, but more of an escape hatch in cases with memory usage issues or
|
|
54
|
-
incompatible `compilerOptions` across workspaces. Workspaces are analyzed
|
|
55
|
-
sequentially to spread out memory usage more evenly, which may prevent crashes
|
|
56
|
-
on large monorepos.
|
|
57
|
-
|
|
58
|
-
## Language Service
|
|
59
|
-
|
|
60
|
-
Knip does not install the TypeScript Language Service (LS) by default. This is
|
|
61
|
-
expensive, as TypeScript needs to set up symbols and caching for the rather slow
|
|
62
|
-
`findReferences` function. Even more so for multiple projects/workspaces.
|
|
63
|
-
|
|
64
|
-
There are two cases that enforce Knip to install the LS:
|
|
65
|
-
|
|
66
|
-
### 1. Class members
|
|
67
|
-
|
|
68
|
-
The `findReferences` function is used to find unused members of imported classes
|
|
69
|
-
(i.e. when the issue type `classMembers` is included).
|
|
70
|
-
|
|
71
|
-
### 2. Include external type definitions
|
|
72
|
-
|
|
73
|
-
When [`--include-libs`][3] is enabled, Knip loads type definitions of external
|
|
74
|
-
dependencies. This will also install the LS to access its `findReferences`
|
|
75
|
-
function. It acts as an extra line of defense: only exports that Knip thinks
|
|
76
|
-
aren't referenced (during the default/fast procedure), will now receive a second
|
|
77
|
-
opinion from `findReferences`.
|
|
78
|
-
|
|
79
26
|
## Metrics
|
|
80
27
|
|
|
81
|
-
Use [the `--performance` flag][
|
|
28
|
+
Use [the `--performance` flag][2] to see how many times potentially expensive
|
|
82
29
|
functions (e.g. `findReferences`) are invoked and how much time is spent in
|
|
83
30
|
those functions. Example usage:
|
|
84
31
|
|
|
85
32
|
```sh
|
|
86
|
-
knip --
|
|
33
|
+
knip --performance
|
|
87
34
|
```
|
|
88
35
|
|
|
89
36
|
## ignoreExportsUsedInFile
|
|
90
37
|
|
|
91
|
-
The [ignoreExportsUsedInFile][
|
|
38
|
+
The [ignoreExportsUsedInFile][3] option slows down the process slightly.
|
|
92
39
|
Typically, anywhere between 0.25% and 10% of total running time. To find out:
|
|
93
40
|
|
|
94
41
|
```sh
|
|
@@ -98,11 +45,9 @@ knip --performance-fn hasRefsInFile
|
|
|
98
45
|
## A last resort
|
|
99
46
|
|
|
100
47
|
In case Knip is unbearably slow (or even crashes), you could resort to [lint
|
|
101
|
-
individual workspaces][
|
|
48
|
+
individual workspaces][4].
|
|
102
49
|
|
|
103
50
|
[1]: ./configuring-project-files.md
|
|
104
|
-
[2]: ../reference/cli.md#--
|
|
105
|
-
[3]: ../
|
|
106
|
-
[4]: ../
|
|
107
|
-
[5]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
108
|
-
[6]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
51
|
+
[2]: ../reference/cli.md#--performance
|
|
52
|
+
[3]: ../reference/configuration.md#ignoreexportsusedinfile
|
|
53
|
+
[4]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
package/src/docs/docs/index.mdx
CHANGED
|
@@ -3,7 +3,7 @@ title: Declutter your JavaScript & TypeScript projects
|
|
|
3
3
|
description: Project linter to find unused dependencies, exports and files
|
|
4
4
|
template: splash
|
|
5
5
|
hero:
|
|
6
|
-
title: Knip
|
|
6
|
+
title: Knip v6
|
|
7
7
|
tagline: Declutter your JavaScript & TypeScript projects
|
|
8
8
|
image:
|
|
9
9
|
file: ../../assets/logo.svg
|
|
@@ -12,8 +12,8 @@ hero:
|
|
|
12
12
|
link: ./overview/getting-started
|
|
13
13
|
icon: right-arrow
|
|
14
14
|
variant: primary
|
|
15
|
-
- text: 'NEW: Knip
|
|
16
|
-
link: /blog/
|
|
15
|
+
- text: 'NEW: Knip v6'
|
|
16
|
+
link: /blog/knip-v6
|
|
17
17
|
icon: rocket
|
|
18
18
|
variant: secondary
|
|
19
19
|
- text: View on GitHub
|
|
@@ -46,7 +46,7 @@ folder:
|
|
|
46
46
|
|
|
47
47
|
```json title="knip.json"
|
|
48
48
|
{
|
|
49
|
-
"$schema": "https://unpkg.com/knip@
|
|
49
|
+
"$schema": "https://unpkg.com/knip@6/schema.json",
|
|
50
50
|
"entry": ["src/index.ts", "scripts/{build,create}.js"],
|
|
51
51
|
"project": ["src/**/*.ts", "scripts/**/*.js"]
|
|
52
52
|
}
|