knip 2.19.3 → 2.19.4
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/README.md +399 -339
- package/dist/ConfigurationValidator.js +12 -13
- package/dist/plugins/commitizen/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -32,20 +32,55 @@ Knip shines in both small and large projects. It's a fresh take on keeping your
|
|
|
32
32
|
[![An orange cow with scissors, Van Gogh style][7]][6] <sup>_“An orange cow with scissors, Van Gogh style” - generated
|
|
33
33
|
with OpenAI_</sup>
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Contents
|
|
36
|
+
|
|
37
|
+
- [Getting Started][8]
|
|
38
|
+
- [Installation][9]
|
|
39
|
+
- [Default Configuration][10]
|
|
40
|
+
- [Let's Go!][11]
|
|
41
|
+
- [Configuration][12]
|
|
42
|
+
- [Entry Files][13]
|
|
43
|
+
- [Workspaces][1]
|
|
44
|
+
- [Plugins][2]
|
|
45
|
+
- [Compilers][3]
|
|
46
|
+
- [Ignore files, binaries, dependencies and workspaces][14]
|
|
47
|
+
- [Public exports][15]
|
|
48
|
+
- [Ignore exports used in file][16]
|
|
49
|
+
- [Include exports in entry files][17]
|
|
50
|
+
- [Paths][18]
|
|
51
|
+
- [Production Mode][19]
|
|
52
|
+
- [Strict][20]
|
|
53
|
+
- [Plugins][21]
|
|
54
|
+
- [Output][22]
|
|
55
|
+
- [Screenshots][23]
|
|
56
|
+
- [Reading the report][24]
|
|
57
|
+
- [Rules & Filters][25]
|
|
58
|
+
- [Reporters][4]
|
|
59
|
+
- [Fixing Issues][26]
|
|
60
|
+
- [Command Line Options][27]
|
|
61
|
+
- [Potential boost with `--no-gitignore`][28]
|
|
62
|
+
- [Comparison & Migration][29]
|
|
63
|
+
- [depcheck][30]
|
|
64
|
+
- [unimported][31]
|
|
65
|
+
- [ts-unused-exports][32]
|
|
66
|
+
- [ts-prune][33]
|
|
67
|
+
- [Projects using Knip][34]
|
|
68
|
+
- [Articles, etc.][35]
|
|
69
|
+
- [Why "Knip"?][36]
|
|
70
|
+
- [Really, another unused file/dependency/export finder?][37]
|
|
71
|
+
- [Contributors][38]
|
|
72
|
+
|
|
73
|
+
## Getting Started
|
|
74
|
+
|
|
75
|
+
### Installation
|
|
36
76
|
|
|
37
77
|
npm install -D knip
|
|
38
78
|
|
|
39
79
|
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6.
|
|
40
80
|
|
|
41
|
-
|
|
81
|
+
### Default Configuration
|
|
42
82
|
|
|
43
|
-
|
|
44
|
-
experimental knowledge base, answers may be incorrect.
|
|
45
|
-
|
|
46
|
-
## Configuration
|
|
47
|
-
|
|
48
|
-
Knip has good defaults and you can run it without any configuration. Here's the default:
|
|
83
|
+
Knip has good defaults and you can run it without any configuration. The (simplified) default config:
|
|
49
84
|
|
|
50
85
|
```json
|
|
51
86
|
{
|
|
@@ -54,37 +89,7 @@ Knip has good defaults and you can run it without any configuration. Here's the
|
|
|
54
89
|
}
|
|
55
90
|
```
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- `index`, `main` and `cli`
|
|
60
|
-
- `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`
|
|
61
|
-
|
|
62
|
-
This means files like `main.cjs` and `src/cli.ts` are automatically added as entry files.
|
|
63
|
-
|
|
64
|
-
### Entry Files
|
|
65
|
-
|
|
66
|
-
Knip looks for entry files at those default locations, but also in other places:
|
|
67
|
-
|
|
68
|
-
- The `main`, `bin` and `exports` fields of `package.json`.
|
|
69
|
-
- [Plugins][2] such as for Next.js, Remix, Gatsby or Svelte add entry files.
|
|
70
|
-
- The `scripts` in package.json or other scripts may provide entry files.
|
|
71
|
-
|
|
72
|
-
Knip does this for each [workspace][1] it finds, trying to minimize the configuration to suit your project. In a
|
|
73
|
-
perfectly boring world where everything is according to defaults you wouldn't even need a `knip.json` file at all.
|
|
74
|
-
|
|
75
|
-
Larger projects tend to have more things customized, and therefore probably get more out of Knip with a configuration
|
|
76
|
-
file. Let's say you are using `.ts` files exclusively and have all source files only in the `src` directory:
|
|
77
|
-
|
|
78
|
-
```json
|
|
79
|
-
{
|
|
80
|
-
"$schema": "https://unpkg.com/knip@2/schema.json",
|
|
81
|
-
"entry": ["src/index.ts"],
|
|
82
|
-
"project": ["src/**/*.ts"]
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
|
|
87
|
-
contain all files to match against the files resolved from the entry files, including potentially unused files.
|
|
92
|
+
There's more, jump to [Entry Files][13] for details.
|
|
88
93
|
|
|
89
94
|
Places where Knip looks for configuration (ordered by priority):
|
|
90
95
|
|
|
@@ -96,7 +101,7 @@ Places where Knip looks for configuration (ordered by priority):
|
|
|
96
101
|
- `knip.js`
|
|
97
102
|
- `package.json#knip`
|
|
98
103
|
|
|
99
|
-
|
|
104
|
+
You can use a dynamic `knip.ts` with TypeScript if you prefer:
|
|
100
105
|
|
|
101
106
|
```ts
|
|
102
107
|
import type { KnipConfig } from 'knip';
|
|
@@ -109,191 +114,59 @@ const config: KnipConfig = {
|
|
|
109
114
|
export default config;
|
|
110
115
|
```
|
|
111
116
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
```json
|
|
115
|
-
{
|
|
116
|
-
"scripts": {
|
|
117
|
-
"knip": "knip"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine with
|
|
123
|
-
`yarn` or `pnpm` as well.
|
|
124
|
-
|
|
125
|
-
Using workspaces in a monorepo? Please see [workspaces][1] for more details about configuring them.
|
|
126
|
-
|
|
127
|
-
## Command-line options
|
|
128
|
-
|
|
129
|
-
$ npx knip --help
|
|
130
|
-
✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
|
|
131
|
-
|
|
132
|
-
Usage: knip [options]
|
|
133
|
-
|
|
134
|
-
Options:
|
|
135
|
-
-c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
|
|
136
|
-
-t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)
|
|
137
|
-
--production Analyze only production source files (e.g. no tests, devDependencies, exported types)
|
|
138
|
-
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
139
|
-
--workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
|
|
140
|
-
--no-gitignore Don't use .gitignore
|
|
141
|
-
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
142
|
-
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
143
|
-
--dependencies Shortcut for --include dependencies,unlisted,unresolved
|
|
144
|
-
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
145
|
-
--include-entry-exports Include entry files when reporting unused exports
|
|
146
|
-
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
147
|
-
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
|
|
148
|
-
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
149
|
-
--no-config-hints Suppress configuration hints
|
|
150
|
-
--no-exit-code Always exit with code zero (0)
|
|
151
|
-
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
152
|
-
-d, --debug Show debug output
|
|
153
|
-
--debug-file-filter Filter for files in debug output (regex as string)
|
|
154
|
-
--performance Measure count and running time of expensive functions and display stats table
|
|
155
|
-
-h, --help Print this help text
|
|
156
|
-
-V, --version Print version
|
|
157
|
-
|
|
158
|
-
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
|
|
159
|
-
|
|
160
|
-
Examples:
|
|
161
|
-
|
|
162
|
-
$ knip
|
|
163
|
-
$ knip --production
|
|
164
|
-
$ knip --workspace packages/client --include files,dependencies
|
|
165
|
-
$ knip -c ./config/knip.json --reporter compact
|
|
166
|
-
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
167
|
-
$ knip --debug --debug-file-filter '(specific|particular)-module'
|
|
168
|
-
|
|
169
|
-
More documentation and bug reports: https://github.com/webpro/knip
|
|
170
|
-
|
|
171
|
-
## Screenshots
|
|
172
|
-
|
|
173
|
-
Here's an example run using the default reporter:
|
|
174
|
-
|
|
175
|
-
<img src="./assets/screenshot-exports.png" alt="example output of exported values and types" width="578">
|
|
176
|
-
|
|
177
|
-
This example shows more output related to unused and unlisted dependencies:
|
|
178
|
-
|
|
179
|
-
<img src="./assets/screenshot-dependencies.png" alt="example output of dependencies" width="578">
|
|
117
|
+
Use `--config path/to/knip.json` to use a different location.
|
|
180
118
|
|
|
181
|
-
|
|
119
|
+
### Let's Go!
|
|
182
120
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
| Key | Title | Description |
|
|
186
|
-
| :---------------- | :---------------------------------- | :---------------------------------------------------- |
|
|
187
|
-
| `files` | Unused files | unable to find references to this file |
|
|
188
|
-
| `dependencies` | Unused dependencies | unable to find references to this dependency |
|
|
189
|
-
| `devDependencies` | Unused devDependencies | unable to find references to this devDependency |
|
|
190
|
-
| `unlisted` | Unlisted dependencies | used dependencies not listed in package.json |
|
|
191
|
-
| `binaries` | Unlisted binaries | binaries from dependencies not in package.json |
|
|
192
|
-
| `unresolved` | Unresolved imports | unable to resolve this (import) specifier |
|
|
193
|
-
| `exports` | Unused exports | unable to find references to this export |
|
|
194
|
-
| `nsExports` | Unused exports in namespaces | unable to find direct references to this export _(1)_ |
|
|
195
|
-
| `types` | Unused exported types | unable to find references to this exported type |
|
|
196
|
-
| `nsTypes` | Unused exported types in namespaces | unable to find direct references to this export _(1)_ |
|
|
197
|
-
| `enumMembers` | Unused exported enum members | unable to find references to this enum member |
|
|
198
|
-
| `classMembers` | Unused exported class members | unable to find references to this class member |
|
|
199
|
-
| `duplicates` | Duplicate exports | the same thing is exported more than once |
|
|
200
|
-
|
|
201
|
-
When an issue type has zero issues, it is not shown.
|
|
202
|
-
|
|
203
|
-
Getting too many reported issues and false positives? Read more about [handling issues][10].
|
|
204
|
-
|
|
205
|
-
_(1)_ The variable or type is not referenced directly and has become a member of a namespace. Knip can't find a
|
|
206
|
-
reference to it, so you can _probably_ remove it.
|
|
207
|
-
|
|
208
|
-
## Output
|
|
209
|
-
|
|
210
|
-
### Rules
|
|
211
|
-
|
|
212
|
-
Use `rules` in the configuration to customize the issue types that count towards the total error count, or to exclude
|
|
213
|
-
them altogether.
|
|
214
|
-
|
|
215
|
-
- `error` (default): printed, adds to total error count (similar to the `--include` filter)
|
|
216
|
-
- `warn`: printed in faded/grey color, does not add to error count (i.e. the exit code)
|
|
217
|
-
- `off`: not printed, does not add to error count (similar to the `--exclude` filter)
|
|
218
|
-
|
|
219
|
-
Example:
|
|
121
|
+
Run the checks with `npx knip`. Or first add this script to `package.json`:
|
|
220
122
|
|
|
221
123
|
```json
|
|
222
124
|
{
|
|
223
|
-
"
|
|
224
|
-
"
|
|
225
|
-
"classMembers": "off",
|
|
226
|
-
"duplicates": "off"
|
|
125
|
+
"scripts": {
|
|
126
|
+
"knip": "knip"
|
|
227
127
|
}
|
|
228
128
|
}
|
|
229
129
|
```
|
|
230
130
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
|
|
234
|
-
apply filters or configurations only to a specific issue type.
|
|
235
|
-
|
|
236
|
-
### Filters
|
|
237
|
-
|
|
238
|
-
You can `--include` or `--exclude` any of the reported issue types to slice & dice the report to your needs.
|
|
239
|
-
Alternatively, they can be added to the configuration (e.g. `"exclude": ["dependencies"]`).
|
|
240
|
-
|
|
241
|
-
Use `--include` to report only specific issue types (the following example commands do the same):
|
|
242
|
-
|
|
243
|
-
knip --include files --include dependencies
|
|
244
|
-
knip --include files,dependencies
|
|
131
|
+
Then use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine
|
|
132
|
+
with `yarn` or `pnpm` as well.
|
|
245
133
|
|
|
246
|
-
|
|
134
|
+
See [Command Line Options][27] for an overview of available CLI options.
|
|
247
135
|
|
|
248
|
-
|
|
136
|
+
## Configuration
|
|
249
137
|
|
|
250
|
-
|
|
138
|
+
### Entry Files
|
|
251
139
|
|
|
252
|
-
|
|
140
|
+
In addition to `index.js`, the following file names and extensions are also considered entry files:
|
|
253
141
|
|
|
254
|
-
|
|
142
|
+
- `index`, `main` and `cli`
|
|
143
|
+
- `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`
|
|
255
144
|
|
|
256
|
-
|
|
145
|
+
This means files like `main.cjs` and `src/cli.ts` are automatically added as entry files. Knip looks for entry files at
|
|
146
|
+
those default locations, but also in other places:
|
|
257
147
|
|
|
258
|
-
-
|
|
259
|
-
-
|
|
260
|
-
-
|
|
261
|
-
- Filters have two groups (`--dependencies` and `--types`), rules don't have any grouping.
|
|
148
|
+
- The `main`, `bin` and `exports` fields of `package.json`.
|
|
149
|
+
- [Plugins][2] such as for Next.js, Remix, Gatsby or Svelte add entry files.
|
|
150
|
+
- The `scripts` in package.json or other scripts may provide entry files.
|
|
262
151
|
|
|
263
|
-
|
|
152
|
+
Knip does this for each [workspace][1] it finds, trying to minimize the configuration to suit your project. In a
|
|
153
|
+
perfectly boring world where everything is according to defaults you wouldn't even need a `knip.json` file at all.
|
|
264
154
|
|
|
265
|
-
|
|
155
|
+
Larger projects tend to have more things customized, and therefore probably get more out of Knip with a configuration
|
|
156
|
+
file. Let's say you are using `.ts` files exclusively and have all source files only in the `src` directory:
|
|
266
157
|
|
|
267
158
|
```json
|
|
268
159
|
{
|
|
269
|
-
"
|
|
270
|
-
"
|
|
271
|
-
"
|
|
272
|
-
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
|
|
160
|
+
"$schema": "https://unpkg.com/knip@2/schema.json",
|
|
161
|
+
"entry": ["src/index.ts"],
|
|
162
|
+
"project": ["src/**/*.ts"]
|
|
273
163
|
}
|
|
274
164
|
```
|
|
275
165
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
## What's next?
|
|
279
|
-
|
|
280
|
-
This is the fun part! Knip, knip, knip ✂️
|
|
281
|
-
|
|
282
|
-
As always, make sure to back up files or use Git before deleting files or making changes. Run tests to verify results.
|
|
283
|
-
|
|
284
|
-
- Unused files can be removed.
|
|
285
|
-
- Unused dependencies can be removed from `package.json`.
|
|
286
|
-
- Unlisted dependencies should be added to `package.json`.
|
|
287
|
-
- Unresolved imports should be reviewed.
|
|
288
|
-
- Unused exports and types: remove the `export` keyword in front of unused exports. Then you can see whether the
|
|
289
|
-
variable or type is used within the same file. If this is not the case, it can be removed.
|
|
290
|
-
- Duplicate exports can be removed so they're exported only once.
|
|
291
|
-
|
|
292
|
-
🔁 Repeat the process to reveal new unused files and exports. Sometimes it's so liberating to remove things!
|
|
293
|
-
|
|
294
|
-
Getting too many reported issues and false positives? Read more about [handling issues][10].
|
|
166
|
+
The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
|
|
167
|
+
contain all files to match against the files resolved from the entry files, including potentially unused files.
|
|
295
168
|
|
|
296
|
-
|
|
169
|
+
### Workspaces
|
|
297
170
|
|
|
298
171
|
Workspaces are handled out-of-the-box by Knip. Every workspace is part of the analysis.
|
|
299
172
|
|
|
@@ -328,15 +201,13 @@ The root workspace is named `"."` under `workspaces` (like in the example).
|
|
|
328
201
|
Knip supports workspaces as defined in three possible locations:
|
|
329
202
|
|
|
330
203
|
- In the `workspaces` array in `package.json` (npm, Yarn, Lerna).
|
|
331
|
-
- In the `workspaces.packages` array in `package.json` (legacy).
|
|
332
204
|
- In the `packages` array in `pnpm-workspace.yaml` (pnpm).
|
|
205
|
+
- In the `workspaces.packages` array in `package.json` (legacy).
|
|
333
206
|
- In the `workspaces` object in Knip configuration.
|
|
334
207
|
|
|
335
208
|
The `workspaces` in Knip configuration not already defined in the root `package.json` or `pnpm-workspace.yaml` are
|
|
336
209
|
added. Knip requires a `package.json` file in each workspace directory.
|
|
337
210
|
|
|
338
|
-
The `ignore`, `ignoreBinaries` and `ignoreDependencies` options are available inside workspace configurations.
|
|
339
|
-
|
|
340
211
|
Here's some example output when running Knip in a workspace:
|
|
341
212
|
|
|
342
213
|
<img src="./assets/screenshot-workspaces.png" alt="example output in workspaces" width="578">
|
|
@@ -345,12 +216,14 @@ Use `--debug` to get more verbose output.
|
|
|
345
216
|
|
|
346
217
|
Use `--workspace [dir]` to analyze a single workspace (including its ancestors).
|
|
347
218
|
|
|
348
|
-
|
|
219
|
+
The `ignore`, `ignoreBinaries` and `ignoreDependencies` options are available inside workspace configurations.
|
|
220
|
+
|
|
221
|
+
### Plugins
|
|
349
222
|
|
|
350
223
|
Plugins tell Knip where to look for configuration and entry files, and if necessary have a custom dependency finder.
|
|
351
224
|
Knip plugins are automatically activated, you don't need to install or configure anything.
|
|
352
225
|
|
|
353
|
-
To explain what they do, here's a quick example
|
|
226
|
+
To explain what they do, here's a quick example `.eslintrc.json` configuration file (for ESLint):
|
|
354
227
|
|
|
355
228
|
```json
|
|
356
229
|
{
|
|
@@ -415,18 +288,18 @@ themselves and/or `entry` files for Knip to analyze.
|
|
|
415
288
|
|
|
416
289
|
See each plugin's documentation for its default values.
|
|
417
290
|
|
|
418
|
-
|
|
291
|
+
#### `config`
|
|
419
292
|
|
|
420
293
|
Plugins usually include `config` files. They are handled by the plugin's custom dependency finder, which returns all
|
|
421
294
|
dependencies referenced in the files it is given. Knip handles the rest to determine which of those dependencies are
|
|
422
295
|
unused or missing.
|
|
423
296
|
|
|
424
|
-
|
|
297
|
+
#### `entry`
|
|
425
298
|
|
|
426
299
|
Other configuration files use `require` or `import` statements to use dependencies, so they don't need special handing
|
|
427
300
|
and can be analyzed like any other source file. That's why these configuration files are also used as `entry` files.
|
|
428
301
|
|
|
429
|
-
|
|
302
|
+
#### Override plugin configuration
|
|
430
303
|
|
|
431
304
|
Usually, no custom configuration is required for plugins, but if your project uses custom file locations then Knip
|
|
432
305
|
allows you to override any defaults. Let's take Cypress for example. By default it uses `cypress.config.js`, but your
|
|
@@ -441,10 +314,10 @@ has them at `e2e-tests/*.spec.ts`. Here's how to configure this:
|
|
|
441
314
|
}
|
|
442
315
|
```
|
|
443
316
|
|
|
444
|
-
|
|
317
|
+
#### Multi-project repositories
|
|
445
318
|
|
|
446
319
|
Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
|
|
447
|
-
repository (such as the [Nx "intregrated repo" style][
|
|
320
|
+
repository (such as the [Nx "intregrated repo" style][39]). Let's assume some of these projects are apps and have their
|
|
448
321
|
own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
|
|
449
322
|
|
|
450
323
|
```json
|
|
@@ -455,24 +328,24 @@ own Cypress configuration and test files. In that case, we could configure the C
|
|
|
455
328
|
}
|
|
456
329
|
```
|
|
457
330
|
|
|
458
|
-
|
|
331
|
+
#### Disable a plugin
|
|
459
332
|
|
|
460
333
|
In case a plugin causes issues, it can be disabled by using `false` as its value (e.g. `"webpack": false`).
|
|
461
334
|
|
|
462
|
-
|
|
335
|
+
#### Create a new plugin
|
|
463
336
|
|
|
464
|
-
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][
|
|
337
|
+
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][40]. This
|
|
465
338
|
guide also contains more details if you want to learn more about plugins and why they are useful.
|
|
466
339
|
|
|
467
|
-
|
|
340
|
+
### Compilers
|
|
468
341
|
|
|
469
|
-
|
|
470
|
-
|
|
342
|
+
Compilers allow to include files that are not JavaScript or TypeScript in the process of finding unused or missing
|
|
343
|
+
dependencies (e.g. `.mdx`, `.vue` and `.svelte` files).
|
|
471
344
|
|
|
472
|
-
|
|
473
|
-
where each key represents the extension and the value is a function that takes the contents of these files
|
|
474
|
-
returns JavaScript or TypeScript as output. Here is an example that compiles `.mdx` files to JavaScript so
|
|
475
|
-
and their imports and exports become part of the analysis:
|
|
345
|
+
This requires using a dynamic `knip.js` or `knip.ts` configuration file. Provide a `compilers` object in the
|
|
346
|
+
configuration where each key represents the extension and the value is a function that takes the contents of these files
|
|
347
|
+
as input and returns JavaScript or TypeScript as output. Here is an example that compiles `.mdx` files to JavaScript so
|
|
348
|
+
these files and their imports and exports become part of the analysis:
|
|
476
349
|
|
|
477
350
|
```js
|
|
478
351
|
import { compileSync } from 'mdx-js/mdx';
|
|
@@ -484,7 +357,95 @@ export default {
|
|
|
484
357
|
};
|
|
485
358
|
```
|
|
486
359
|
|
|
487
|
-
Read [Compilers][
|
|
360
|
+
Read [Compilers][41] for more details and examples.
|
|
361
|
+
|
|
362
|
+
### Ignore files, binaries, dependencies and workspaces
|
|
363
|
+
|
|
364
|
+
There are a few ways to tell Knip to ignore certain files, binaries, dependencies and workspaces. Some examples:
|
|
365
|
+
|
|
366
|
+
```json
|
|
367
|
+
{
|
|
368
|
+
"ignore": ["**/*.d.ts", "**/fixtures"],
|
|
369
|
+
"ignoreBinaries": ["zip", "docker-compose"],
|
|
370
|
+
"ignoreDependencies": ["hidden-package"],
|
|
371
|
+
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
These can also be configured per workspace (except for `ignoreWorkspaces`).
|
|
376
|
+
|
|
377
|
+
### Public exports
|
|
378
|
+
|
|
379
|
+
Sometimes a file that's not an entry file has one or more exports that are public and should not be reported as unused.
|
|
380
|
+
Such variables and types can be marked with the JSDoc `@public` tag:
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
/**
|
|
384
|
+
* Merge two objects.
|
|
385
|
+
*
|
|
386
|
+
* @public
|
|
387
|
+
*/
|
|
388
|
+
|
|
389
|
+
export const merge = function () {};
|
|
390
|
+
|
|
391
|
+
/** @public */
|
|
392
|
+
export const split = function () {};
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Knip does not report public exports and types as unused.
|
|
396
|
+
|
|
397
|
+
### Ignore exports used in file
|
|
398
|
+
|
|
399
|
+
In files with multiple exports, some of them might be used only internally. If these exports should not be reported,
|
|
400
|
+
there is a `ignoreExportsUsedInFile` option available. With this option enabled, you don't need to mark everything
|
|
401
|
+
`@public` separately and when something is no longer used internally, it will still be reported.
|
|
402
|
+
|
|
403
|
+
```json
|
|
404
|
+
{
|
|
405
|
+
"ignoreExportsUsedInFile": true
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
In a more fine-grained manner, you can also ignore only specific issue types:
|
|
410
|
+
|
|
411
|
+
```json
|
|
412
|
+
{
|
|
413
|
+
"ignoreExportsUsedInFile": {
|
|
414
|
+
"interface": true,
|
|
415
|
+
"type": true
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Include exports in entry files
|
|
421
|
+
|
|
422
|
+
When a repository is self-contained or private, you may want to include entry files when reporting unused exports:
|
|
423
|
+
|
|
424
|
+
knip --include-entry-exports
|
|
425
|
+
|
|
426
|
+
Knip will also report unused exports in entry source files and scripts (such as those referenced in `package.json`). But
|
|
427
|
+
not in entry and configuration files from plugins, such as `next.config.js` or `src/routes/+page.svelte`.
|
|
428
|
+
|
|
429
|
+
### Paths
|
|
430
|
+
|
|
431
|
+
Tools like TypeScript, Webpack and Babel support import aliases in various ways. Knip automatically includes
|
|
432
|
+
`compilerOptions.paths` from the TypeScript configuration, but does not (yet) automatically find other types of import
|
|
433
|
+
aliases. They can be configured manually:
|
|
434
|
+
|
|
435
|
+
```json
|
|
436
|
+
{
|
|
437
|
+
"$schema": "https://unpkg.com/knip@2/schema.json",
|
|
438
|
+
"paths": {
|
|
439
|
+
"@lib": ["./lib/index.ts"],
|
|
440
|
+
"@lib/*": ["./lib/*"]
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Each workspace can also have its own `paths` configured. Knip `paths` follow the TypeScript semantics:
|
|
446
|
+
|
|
447
|
+
- Path values are an array of relative paths.
|
|
448
|
+
- Paths without an `*` are exact matches.
|
|
488
449
|
|
|
489
450
|
## Production Mode
|
|
490
451
|
|
|
@@ -521,110 +482,192 @@ Additionally, the `--strict` flag can be used to:
|
|
|
521
482
|
### Plugins
|
|
522
483
|
|
|
523
484
|
Plugins also have this distinction. For instance, Next.js entry files for pages (`pages/**/*.tsx`) and Remix routes
|
|
524
|
-
(`app/routes/**/*.tsx`)
|
|
525
|
-
|
|
485
|
+
(`app/routes/**/*.tsx`) represent production code, while Jest and Storybook entry files (e.g. `*.spec.ts` or
|
|
486
|
+
`*.stories.js`) do not. All of this is handled automatically by Knip and its plugins.
|
|
526
487
|
|
|
527
|
-
##
|
|
488
|
+
## Output
|
|
528
489
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
490
|
+
### Screenshots
|
|
491
|
+
|
|
492
|
+
Here's an example run using the default reporter:
|
|
493
|
+
|
|
494
|
+
<img src="./assets/screenshot-exports.png" alt="example output of exported values and types" width="578">
|
|
495
|
+
|
|
496
|
+
This example shows more output related to unused and unlisted dependencies:
|
|
497
|
+
|
|
498
|
+
<img src="./assets/screenshot-dependencies.png" alt="example output of dependencies" width="578">
|
|
499
|
+
|
|
500
|
+
### Reading the report
|
|
501
|
+
|
|
502
|
+
The report contains the following types of issues:
|
|
503
|
+
|
|
504
|
+
| Title | Description | Key |
|
|
505
|
+
| :---------------------------------- | :---------------------------------------------- | :------------- |
|
|
506
|
+
| Unused files | unable to find references to this file | `files` |
|
|
507
|
+
| Unused dependencies | unable to find references to this dependency | `dependencies` |
|
|
508
|
+
| Unused devDependencies | unable to find references to this devDependency | `dependencies` |
|
|
509
|
+
| Unlisted dependencies | used dependencies not listed in package.json | `unlisted` |
|
|
510
|
+
| Unlisted binaries | binaries from deps not listed in package.json | `binaries` |
|
|
511
|
+
| Unresolved imports | unable to resolve this (import) specifier | `unresolved` |
|
|
512
|
+
| Unused exports | unable to find references to this export | `exports` |
|
|
513
|
+
| Unused exports in namespaces | unable to find direct references to this export | `nsExports` |
|
|
514
|
+
| Unused exported types | unable to find references to this exported type | `types` |
|
|
515
|
+
| Unused exported types in namespaces | unable to find direct references to this export | `nsTypes` |
|
|
516
|
+
| Unused exported enum members | unable to find references to this enum member | `enumMembers` |
|
|
517
|
+
| Unused exported class members | unable to find references to this class member | `classMembers` |
|
|
518
|
+
| Duplicate exports | the same thing is exported more than once | `duplicates` |
|
|
519
|
+
|
|
520
|
+
When an issue type has zero issues, it is not shown.
|
|
521
|
+
|
|
522
|
+
Getting too many reported issues and false positives? Read more about [handling issues][42].
|
|
523
|
+
|
|
524
|
+
### Rules & Filters
|
|
525
|
+
|
|
526
|
+
Use rules or filters if you don't (yet) want all issue types Knip reports.
|
|
527
|
+
|
|
528
|
+
#### Rules
|
|
529
|
+
|
|
530
|
+
Use `rules` in the configuration to customize the issue types that count towards the total error count, or to exclude
|
|
531
|
+
them altogether.
|
|
532
|
+
|
|
533
|
+
- `error` (default): printed, adds to total error count (similar to the `--include` filter)
|
|
534
|
+
- `warn`: printed in faded/grey color, does not add to error count (i.e. the exit code)
|
|
535
|
+
- `off`: not printed, does not add to error count (similar to the `--exclude` filter)
|
|
536
|
+
|
|
537
|
+
Example:
|
|
532
538
|
|
|
533
539
|
```json
|
|
534
540
|
{
|
|
535
|
-
"
|
|
536
|
-
|
|
537
|
-
"
|
|
538
|
-
"
|
|
541
|
+
"rules": {
|
|
542
|
+
"files": "warn",
|
|
543
|
+
"classMembers": "off",
|
|
544
|
+
"duplicates": "off"
|
|
539
545
|
}
|
|
540
546
|
}
|
|
541
547
|
```
|
|
542
548
|
|
|
543
|
-
|
|
549
|
+
See [reading the report][24] for the list of issue types.
|
|
544
550
|
|
|
545
|
-
|
|
546
|
-
|
|
551
|
+
The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
|
|
552
|
+
apply filters or configurations only to a specific issue type.
|
|
553
|
+
|
|
554
|
+
#### Filters
|
|
555
|
+
|
|
556
|
+
You can `--include` or `--exclude` any of the reported issue types to slice & dice the report to your needs.
|
|
557
|
+
Alternatively, they can be added to the configuration (e.g. `"exclude": ["dependencies"]`).
|
|
558
|
+
|
|
559
|
+
Use `--include` to report only specific issue types (the following example commands do the same):
|
|
547
560
|
|
|
548
|
-
|
|
561
|
+
knip --include files --include dependencies
|
|
562
|
+
knip --include files,dependencies
|
|
563
|
+
|
|
564
|
+
Use `--exclude` to ignore reports you're not interested in:
|
|
565
|
+
|
|
566
|
+
knip --include files --exclude classMembers,enumMembers
|
|
567
|
+
|
|
568
|
+
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
569
|
+
|
|
570
|
+
See [reading the report][24] for the list of issue types.
|
|
571
|
+
|
|
572
|
+
#### When to use rules or filters
|
|
573
|
+
|
|
574
|
+
Filters are meant to be used as command-line flags, rules allow for more fine-grained configuration.
|
|
575
|
+
|
|
576
|
+
- Rules are more fine-grained since they also have "warn".
|
|
577
|
+
- Rules could be extended in the future.
|
|
578
|
+
- Filters can be set in configuration and from CLI, rules only in configuration.
|
|
579
|
+
- Filters have two groups (`--dependencies` and `--exports`), rules don't have any grouping.
|
|
580
|
+
|
|
581
|
+
### Reporters
|
|
549
582
|
|
|
550
583
|
Knip provides the following built-in reporters:
|
|
551
584
|
|
|
552
585
|
- codeowners
|
|
553
586
|
- compact
|
|
554
587
|
- json
|
|
555
|
-
- symbol
|
|
588
|
+
- symbol (default)
|
|
556
589
|
|
|
557
|
-
|
|
590
|
+
#### Custom Reporters
|
|
558
591
|
|
|
559
592
|
When the provided built-in reporters are not sufficient, a custom reporter can be implemented.
|
|
560
593
|
|
|
561
|
-
Pass `--reporter ./my-reporter` from the command line. The
|
|
562
|
-
CSV file, or sent to a service.
|
|
594
|
+
Pass something like `--reporter ./my-reporter` from the command line. The results are passed to the function from its
|
|
595
|
+
default export and can be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
563
596
|
|
|
564
|
-
Find more details and ideas in [custom reporters][
|
|
597
|
+
Find more details and ideas in [custom reporters][43].
|
|
565
598
|
|
|
566
|
-
##
|
|
567
|
-
|
|
568
|
-
Sometimes a file that's not an entry file has one or more exports that are public and should not be reported as unused.
|
|
569
|
-
Such variables and types can be marked with the JSDoc `@public` tag:
|
|
599
|
+
## Fixing Issues
|
|
570
600
|
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Merge two objects.
|
|
574
|
-
*
|
|
575
|
-
* @public
|
|
576
|
-
*/
|
|
601
|
+
This is the fun part! Knip, knip, knip ✂️
|
|
577
602
|
|
|
578
|
-
|
|
603
|
+
Tip: back up files or use an VCS like Git before deleting files or making changes. Run tests to verify results.
|
|
579
604
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
605
|
+
- Unused files can be removed.
|
|
606
|
+
- Unused dependencies can be removed from `package.json`.
|
|
607
|
+
- Unlisted dependencies should be added to `package.json`.
|
|
608
|
+
- Unresolved imports should be reviewed.
|
|
609
|
+
- Unused exports and types: remove the `export` keyword in front of unused exports. Then you can see whether the
|
|
610
|
+
variable or type is used within the same file. If this is not the case, it can be removed.
|
|
611
|
+
- Duplicate exports can be removed so they're exported only once.
|
|
583
612
|
|
|
584
|
-
|
|
613
|
+
Repeat the process to reveal new unused files and exports. It's so liberating to remove unused things!
|
|
585
614
|
|
|
586
|
-
|
|
615
|
+
Getting too many reported issues and false positives? Read more about [handling issues][44] describing potential causes
|
|
616
|
+
for false positives, and how to handle them.
|
|
587
617
|
|
|
588
|
-
|
|
589
|
-
there is a `ignoreExportsUsedInFile` option available. With this option enabled, you don't need to mark everything
|
|
590
|
-
`@public` separately and when something is no longer used internally, it will still be reported.
|
|
618
|
+
## Command Line Options
|
|
591
619
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
"ignoreExportsUsedInFile": true
|
|
595
|
-
}
|
|
596
|
-
```
|
|
620
|
+
$ npx knip --help
|
|
621
|
+
✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
|
|
597
622
|
|
|
598
|
-
|
|
623
|
+
Usage: knip [options]
|
|
599
624
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
625
|
+
Options:
|
|
626
|
+
-c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
|
|
627
|
+
-t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)
|
|
628
|
+
--production Analyze only production source files (e.g. no tests, devDependencies, exported types)
|
|
629
|
+
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
630
|
+
--workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
|
|
631
|
+
--no-gitignore Don't use .gitignore
|
|
632
|
+
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
633
|
+
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
634
|
+
--dependencies Shortcut for --include dependencies,unlisted,unresolved
|
|
635
|
+
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
636
|
+
--include-entry-exports Include entry files when reporting unused exports
|
|
637
|
+
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
638
|
+
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
|
|
639
|
+
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
640
|
+
--no-config-hints Suppress configuration hints
|
|
641
|
+
--no-exit-code Always exit with code zero (0)
|
|
642
|
+
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
643
|
+
-d, --debug Show debug output
|
|
644
|
+
--debug-file-filter Filter for files in debug output (regex as string)
|
|
645
|
+
--performance Measure count and running time of expensive functions and display stats table
|
|
646
|
+
-h, --help Print this help text
|
|
647
|
+
-V, --version Print version
|
|
608
648
|
|
|
609
|
-
|
|
649
|
+
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
|
|
610
650
|
|
|
611
|
-
|
|
651
|
+
Examples:
|
|
612
652
|
|
|
613
|
-
knip
|
|
653
|
+
$ knip
|
|
654
|
+
$ knip --production
|
|
655
|
+
$ knip --workspace packages/client --include files,dependencies
|
|
656
|
+
$ knip -c ./config/knip.json --reporter compact
|
|
657
|
+
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
658
|
+
$ knip --debug --debug-file-filter '(specific|particular)-module'
|
|
614
659
|
|
|
615
|
-
|
|
616
|
-
not in entry and configuration files from plugins, such as `next.config.js` or `src/routes/+page.svelte`.
|
|
660
|
+
More documentation and bug reports: https://github.com/webpro/knip
|
|
617
661
|
|
|
618
|
-
##
|
|
662
|
+
## Potential boost with `--no-gitignore`
|
|
619
663
|
|
|
620
|
-
|
|
621
|
-
describing potential causes for false positives, and how to handle them.
|
|
664
|
+
To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][45].
|
|
622
665
|
|
|
623
|
-
## Comparison
|
|
666
|
+
## Comparison & Migration
|
|
624
667
|
|
|
625
668
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
626
669
|
|
|
627
|
-
| Feature | **knip** | [depcheck][
|
|
670
|
+
| Feature | **knip** | [depcheck][46] | [unimported][47] | [ts-unused-exports][48] | [ts-prune][49] |
|
|
628
671
|
| :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
629
672
|
| Unused files | ✅ | - | ✅ | - | - |
|
|
630
673
|
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
@@ -644,7 +687,7 @@ This table is an ongoing comparison. Based on their docs (please report any mist
|
|
|
644
687
|
|
|
645
688
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
646
689
|
|
|
647
|
-
|
|
690
|
+
Below some similar commands to get another idea of what Knip does in comparison:
|
|
648
691
|
|
|
649
692
|
### depcheck
|
|
650
693
|
|
|
@@ -660,7 +703,7 @@ The following commands are similar:
|
|
|
660
703
|
unimported
|
|
661
704
|
knip --production --dependencies --include files
|
|
662
705
|
|
|
663
|
-
Also see [production mode][
|
|
706
|
+
Also see [production mode][19].
|
|
664
707
|
|
|
665
708
|
### ts-unused-exports
|
|
666
709
|
|
|
@@ -682,37 +725,23 @@ The following commands are similar:
|
|
|
682
725
|
|
|
683
726
|
Many thanks to some of the early adopters of Knip:
|
|
684
727
|
|
|
685
|
-
- [Block Protocol][
|
|
686
|
-
- [DeepmergeTS][
|
|
687
|
-
- [eslint-plugin-functional][
|
|
688
|
-
- [freeCodeCamp.org][
|
|
689
|
-
- [is-immutable-type][
|
|
690
|
-
- [IsaacScript][
|
|
691
|
-
- [Owncast][
|
|
692
|
-
- [release-it][
|
|
693
|
-
- [Template TypeScript Node Package][
|
|
694
|
-
|
|
695
|
-
## Potential boost with `--no-gitignore`
|
|
696
|
-
|
|
697
|
-
Running Knip on large workspaces with many packages may feel a bit sluggish. Knip looks up `.gitignore` files and uses
|
|
698
|
-
them to filter out matching entry and project files. This increases correctness. However, you might want to disable that
|
|
699
|
-
with `--no-gitignore` and enjoy a significant performance boost. Depending on the contents of the `.gitignore` files,
|
|
700
|
-
the reported issues may be the same. To help determine whether this trade-off might be worth it for you, first check the
|
|
701
|
-
difference in unused files:
|
|
702
|
-
|
|
703
|
-
```shell
|
|
704
|
-
diff <(knip --no-gitignore --include files) <(knip --include files)
|
|
705
|
-
```
|
|
706
|
-
|
|
707
|
-
And to measure the difference of this flag in seconds:
|
|
728
|
+
- [Block Protocol][50]
|
|
729
|
+
- [DeepmergeTS][51]
|
|
730
|
+
- [eslint-plugin-functional][52]
|
|
731
|
+
- [freeCodeCamp.org][53]
|
|
732
|
+
- [is-immutable-type][54]
|
|
733
|
+
- [IsaacScript][55]
|
|
734
|
+
- [Owncast][56]
|
|
735
|
+
- [release-it][57]
|
|
736
|
+
- [Template TypeScript Node Package][58]
|
|
708
737
|
|
|
709
|
-
|
|
710
|
-
SECONDS=0; knip > /dev/null; t1=$SECONDS; SECONDS=0; knip --no-gitignore > /dev/null; t2=$SECONDS; echo "Difference: $((t1 - t2)) seconds"
|
|
711
|
-
```
|
|
738
|
+
## Articles, etc.
|
|
712
739
|
|
|
713
|
-
|
|
740
|
+
- Ask your questions in the [Knip knowledge base][59] (powered by OpenAI and [7-docs][60], experimental!)
|
|
741
|
+
- Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][61]
|
|
742
|
+
- Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][62]
|
|
714
743
|
|
|
715
|
-
## Knip
|
|
744
|
+
## Why "Knip"?
|
|
716
745
|
|
|
717
746
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
718
747
|
for the job. I'm motivated to make Knip perfectly suited for the job of cutting projects to perfection! ✂️
|
|
@@ -728,7 +757,7 @@ each file, and traversing all of this, why not collect the various issues in one
|
|
|
728
757
|
|
|
729
758
|
Special thanks to the wonderful people who have contributed to this project:
|
|
730
759
|
|
|
731
|
-
[![Contributors][
|
|
760
|
+
[![Contributors][64]][63]
|
|
732
761
|
|
|
733
762
|
[1]: #workspaces
|
|
734
763
|
[2]: #plugins
|
|
@@ -737,32 +766,63 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
737
766
|
[5]: #custom-reporters
|
|
738
767
|
[6]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
739
768
|
[7]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
740
|
-
[8]:
|
|
741
|
-
[9]:
|
|
742
|
-
[10]: #
|
|
743
|
-
[11]: #
|
|
769
|
+
[8]: #getting-started
|
|
770
|
+
[9]: #installation
|
|
771
|
+
[10]: #default-configuration
|
|
772
|
+
[11]: #lets-go
|
|
744
773
|
[12]: #configuration
|
|
745
|
-
[13]:
|
|
746
|
-
[14]:
|
|
747
|
-
[15]:
|
|
748
|
-
[16]:
|
|
749
|
-
[17]:
|
|
750
|
-
[18]:
|
|
751
|
-
[19]:
|
|
752
|
-
[20]:
|
|
753
|
-
[21]:
|
|
754
|
-
[22]: #
|
|
755
|
-
[23]:
|
|
756
|
-
[24]:
|
|
757
|
-
[25]:
|
|
758
|
-
[26]:
|
|
759
|
-
[27]:
|
|
760
|
-
[28]:
|
|
761
|
-
[29]:
|
|
762
|
-
[30]:
|
|
763
|
-
[31]:
|
|
764
|
-
[32]:
|
|
765
|
-
[33]:
|
|
774
|
+
[13]: #entry-files
|
|
775
|
+
[14]: #ignore-files-binaries-dependencies-and-workspaces
|
|
776
|
+
[15]: #public-exports
|
|
777
|
+
[16]: #ignore-exports-used-in-file
|
|
778
|
+
[17]: #include-exports-in-entry-files
|
|
779
|
+
[18]: #paths
|
|
780
|
+
[19]: #production-mode
|
|
781
|
+
[20]: #strict
|
|
782
|
+
[21]: #plugins-1
|
|
783
|
+
[22]: #output
|
|
784
|
+
[23]: #screenshots
|
|
785
|
+
[24]: #reading-the-report
|
|
786
|
+
[25]: #rules--filters
|
|
787
|
+
[26]: #fixing-issues
|
|
788
|
+
[27]: #command-line-options
|
|
789
|
+
[28]: #potential-boost-with---no-gitignore
|
|
790
|
+
[29]: #comparison--migration
|
|
791
|
+
[30]: #depcheck
|
|
792
|
+
[31]: #unimported
|
|
793
|
+
[32]: #ts-unused-exports
|
|
794
|
+
[33]: #ts-prune
|
|
795
|
+
[34]: #projects-using-knip
|
|
796
|
+
[35]: #articles-etc
|
|
797
|
+
[36]: #why-knip
|
|
798
|
+
[37]: #really-another-unused-filedependencyexport-finder
|
|
799
|
+
[38]: #contributors
|
|
800
|
+
[39]: https://nx.dev/concepts/integrated-vs-package-based
|
|
801
|
+
[40]: ./docs/writing-a-plugin.md
|
|
802
|
+
[41]: ./docs/compilers.md
|
|
803
|
+
[42]: #handling-issues
|
|
804
|
+
[43]: ./docs/custom-reporters.md
|
|
805
|
+
[44]: ./docs/handling-issues.md
|
|
806
|
+
[45]: ./docs/perf-boost-with-no-gitignore.md
|
|
807
|
+
[46]: https://github.com/depcheck/depcheck
|
|
808
|
+
[47]: https://github.com/smeijer/unimported
|
|
809
|
+
[48]: https://github.com/pzavolinsky/ts-unused-exports
|
|
810
|
+
[49]: https://github.com/nadeesha/ts-prune
|
|
811
|
+
[50]: https://github.com/blockprotocol/blockprotocol
|
|
812
|
+
[51]: https://github.com/RebeccaStevens/deepmerge-ts
|
|
813
|
+
[52]: https://github.com/eslint-functional/eslint-plugin-functional
|
|
814
|
+
[53]: https://github.com/freeCodeCamp/freeCodeCamp
|
|
815
|
+
[54]: https://github.com/RebeccaStevens/is-immutable-type
|
|
816
|
+
[55]: https://github.com/IsaacScript/isaacscript
|
|
817
|
+
[56]: https://github.com/owncast/owncast
|
|
818
|
+
[57]: https://github.com/release-it/release-it
|
|
819
|
+
[58]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
|
|
820
|
+
[59]: https://knip.deno.dev
|
|
821
|
+
[60]: https://github.com/7-docs/7-docs
|
|
822
|
+
[61]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
|
|
823
|
+
[62]: https://effectivetypescript.com/2023/07/29/knip/
|
|
824
|
+
[63]: https://github.com/webpro/knip/graphs/contributors
|
|
825
|
+
[64]: https://contrib.rocks/image?repo=webpro/knip
|
|
766
826
|
[plugin-ava]: ./src/plugins/ava
|
|
767
827
|
[plugin-babel]: ./src/plugins/babel
|
|
768
828
|
[plugin-capacitor]: ./src/plugins/capacitor
|
|
@@ -21,6 +21,17 @@ const issueTypeSchema = z.union([
|
|
|
21
21
|
z.literal('classMembers'),
|
|
22
22
|
]);
|
|
23
23
|
const rulesSchema = z.record(issueTypeSchema, z.enum(['error', 'warn', 'off']));
|
|
24
|
+
const ignoreExportsUsedInFileSchema = z.union([
|
|
25
|
+
z.boolean(),
|
|
26
|
+
z.record(z.union([
|
|
27
|
+
z.literal('class'),
|
|
28
|
+
z.literal('enum'),
|
|
29
|
+
z.literal('function'),
|
|
30
|
+
z.literal('interface'),
|
|
31
|
+
z.literal('member'),
|
|
32
|
+
z.literal('type'),
|
|
33
|
+
]), z.boolean()),
|
|
34
|
+
]);
|
|
24
35
|
const rootConfigurationSchema = z.object({
|
|
25
36
|
rules: rulesSchema.optional(),
|
|
26
37
|
entry: globSchema.optional(),
|
|
@@ -28,19 +39,7 @@ const rootConfigurationSchema = z.object({
|
|
|
28
39
|
paths: pathsSchema.optional(),
|
|
29
40
|
ignore: globSchema.optional(),
|
|
30
41
|
ignoreBinaries: z.array(z.string()).optional(),
|
|
31
|
-
ignoreExportsUsedInFile:
|
|
32
|
-
.union([
|
|
33
|
-
z.boolean(),
|
|
34
|
-
z.record(z.union([
|
|
35
|
-
z.literal('class'),
|
|
36
|
-
z.literal('enum'),
|
|
37
|
-
z.literal('function'),
|
|
38
|
-
z.literal('interface'),
|
|
39
|
-
z.literal('member'),
|
|
40
|
-
z.literal('type'),
|
|
41
|
-
]), z.boolean()),
|
|
42
|
-
])
|
|
43
|
-
.optional(),
|
|
42
|
+
ignoreExportsUsedInFile: ignoreExportsUsedInFileSchema.optional(),
|
|
44
43
|
ignoreDependencies: z.array(z.string()).optional(),
|
|
45
44
|
ignoreWorkspaces: z.array(z.string()).optional(),
|
|
46
45
|
compilers: compilersSchema.optional(),
|
|
@@ -3,7 +3,7 @@ import { hasDependency, load } from '../../util/plugin.js';
|
|
|
3
3
|
export const NAME = 'Commitizen';
|
|
4
4
|
export const ENABLERS = ['commitizen'];
|
|
5
5
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
6
|
-
export const CONFIG_FILE_PATTERNS = ['.czrc', 'package.json'];
|
|
6
|
+
export const CONFIG_FILE_PATTERNS = ['.czrc', '.cz.json', 'package.json'];
|
|
7
7
|
const findPluginDependencies = async (configFilePath, { manifest }) => {
|
|
8
8
|
const config = configFilePath.endsWith('package.json')
|
|
9
9
|
? manifest.config?.commitizen
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.19.
|
|
1
|
+
export declare const version = "2.19.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.19.
|
|
1
|
+
export const version = '2.19.4';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.4",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://github.com/webpro/knip",
|
|
6
6
|
"repository": "github:webpro/knip",
|
|
@@ -62,26 +62,26 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@jest/types": "29.6.1",
|
|
65
|
-
"@npmcli/package-json": "
|
|
65
|
+
"@npmcli/package-json": "5.0.0",
|
|
66
66
|
"@release-it/bumper": "5.1.0",
|
|
67
67
|
"@swc/cli": "0.1.62",
|
|
68
|
-
"@swc/core": "1.3.
|
|
68
|
+
"@swc/core": "1.3.77",
|
|
69
69
|
"@types/eslint": "8.44.2",
|
|
70
70
|
"@types/js-yaml": "4.0.5",
|
|
71
71
|
"@types/micromatch": "4.0.2",
|
|
72
72
|
"@types/minimist": "1.2.2",
|
|
73
|
-
"@types/node": "20.
|
|
73
|
+
"@types/node": "20.5.0",
|
|
74
74
|
"@types/npmcli__map-workspaces": "3.0.1",
|
|
75
75
|
"@types/webpack": "5.28.1",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
77
|
-
"@typescript-eslint/parser": "6.
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "6.4.0",
|
|
77
|
+
"@typescript-eslint/parser": "6.4.0",
|
|
78
78
|
"c8": "8.0.1",
|
|
79
|
-
"eslint": "8.
|
|
79
|
+
"eslint": "8.47.0",
|
|
80
80
|
"eslint-import-resolver-typescript": "3.6.0",
|
|
81
81
|
"eslint-plugin-import": "2.28.0",
|
|
82
82
|
"eslint-plugin-n": "16.0.1",
|
|
83
|
-
"prettier": "3.0.
|
|
84
|
-
"release-it": "16.1.
|
|
83
|
+
"prettier": "3.0.2",
|
|
84
|
+
"release-it": "16.1.5",
|
|
85
85
|
"remark-cli": "11.0.0",
|
|
86
86
|
"remark-preset-webpro": "0.0.3",
|
|
87
87
|
"tsx": "3.12.7",
|