@knip/mcp 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/docs/docs/blog/brief-history.md +30 -0
- package/src/docs/docs/blog/for-editors-and-agents.md +131 -0
- package/src/docs/docs/blog/knip-v3.mdx +88 -0
- package/src/docs/docs/blog/knip-v4.mdx +149 -0
- package/src/docs/docs/blog/knip-v5.mdx +190 -0
- package/src/docs/docs/blog/migration-to-v1.md +65 -0
- package/src/docs/docs/blog/release-notes-v2.md +46 -0
- package/src/docs/docs/blog/slim-down-to-speed-up.md +269 -0
- package/src/docs/docs/blog/state-of-knip.md +191 -0
- package/src/docs/docs/blog/two-years.mdx +107 -0
- package/src/docs/docs/explanations/comparison-and-migration.md +133 -0
- package/src/docs/docs/explanations/entry-files.md +70 -0
- package/src/docs/docs/explanations/plugins.md +347 -0
- package/src/docs/docs/explanations/why-use-knip.md +128 -0
- package/src/docs/docs/features/auto-fix.mdx +348 -0
- package/src/docs/docs/features/compilers.md +172 -0
- package/src/docs/docs/features/integrated-monorepos.md +61 -0
- package/src/docs/docs/features/monorepos-and-workspaces.md +149 -0
- package/src/docs/docs/features/production-mode.md +95 -0
- package/src/docs/docs/features/reporters.md +304 -0
- package/src/docs/docs/features/rules-and-filters.md +102 -0
- package/src/docs/docs/features/script-parser.md +156 -0
- package/src/docs/docs/features/source-mapping.md +100 -0
- package/src/docs/docs/guides/configuring-project-files.md +205 -0
- package/src/docs/docs/guides/contributing.md +24 -0
- package/src/docs/docs/guides/handling-issues.mdx +708 -0
- package/src/docs/docs/guides/issue-reproduction.md +103 -0
- package/src/docs/docs/guides/namespace-imports.md +125 -0
- package/src/docs/docs/guides/performance.md +108 -0
- package/src/docs/docs/guides/troubleshooting.md +133 -0
- package/src/docs/docs/guides/using-knip-in-ci.md +50 -0
- package/src/docs/docs/guides/working-with-commonjs.md +72 -0
- package/src/docs/docs/index.mdx +160 -0
- package/src/docs/docs/overview/configuration.md +104 -0
- package/src/docs/docs/overview/features.md +66 -0
- package/src/docs/docs/overview/getting-started.mdx +205 -0
- package/src/docs/docs/overview/screenshots-videos.md +42 -0
- package/src/docs/docs/playground.mdx +38 -0
- package/src/docs/docs/reference/cli.md +511 -0
- package/src/docs/docs/reference/configuration-hints.md +146 -0
- package/src/docs/docs/reference/configuration.md +430 -0
- package/src/docs/docs/reference/dynamic-configuration.mdx +72 -0
- package/src/docs/docs/reference/faq.md +493 -0
- package/src/docs/docs/reference/integrations.md +105 -0
- package/src/docs/docs/reference/issue-types.md +45 -0
- package/src/docs/docs/reference/jsdoc-tsdoc-tags.md +133 -0
- package/src/docs/docs/reference/known-issues.md +86 -0
- package/src/docs/docs/reference/plugins/.gitkeep +0 -0
- package/src/docs/docs/reference/plugins.md +146 -0
- package/src/docs/docs/reference/related-tooling.md +46 -0
- package/src/docs/docs/sponsors.mdx +64 -0
- package/src/docs/docs/typescript/unused-dependencies.md +86 -0
- package/src/docs/docs/typescript/unused-exports.md +87 -0
- package/src/docs/docs/writing-a-plugin/argument-parsing.md +202 -0
- package/src/docs/docs/writing-a-plugin/index.md +392 -0
- package/src/docs/docs/writing-a-plugin/inputs.md +162 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CLI Arguments
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## General
|
|
6
|
+
|
|
7
|
+
### `--help`
|
|
8
|
+
|
|
9
|
+
Shortcut: `-h`
|
|
10
|
+
|
|
11
|
+
Prints a summary of this page.
|
|
12
|
+
|
|
13
|
+
### `--version`
|
|
14
|
+
|
|
15
|
+
Shortcut: `-V`
|
|
16
|
+
|
|
17
|
+
Print the version number.
|
|
18
|
+
|
|
19
|
+
### `--no-progress`
|
|
20
|
+
|
|
21
|
+
Shortcut: `-n`
|
|
22
|
+
|
|
23
|
+
Don't show dynamic progress updates. Progress is automatically disabled in CI
|
|
24
|
+
environments.
|
|
25
|
+
|
|
26
|
+
### `--config [file]`
|
|
27
|
+
|
|
28
|
+
Use an alternative path for the configuration file. Default locations:
|
|
29
|
+
|
|
30
|
+
- `knip.json`
|
|
31
|
+
- `knip.jsonc`
|
|
32
|
+
- `.knip.json`
|
|
33
|
+
- `.knip.jsonc`
|
|
34
|
+
- `knip.js`
|
|
35
|
+
- `knip.ts`
|
|
36
|
+
- `package.json#knip`
|
|
37
|
+
|
|
38
|
+
Shortcut: `-c`
|
|
39
|
+
|
|
40
|
+
### `--use-tsconfig-files`
|
|
41
|
+
|
|
42
|
+
Use `tsconfig.json` to define project files (override `project` patterns).
|
|
43
|
+
|
|
44
|
+
### `--tsConfig [file]`
|
|
45
|
+
|
|
46
|
+
Shortcut: `-t`
|
|
47
|
+
|
|
48
|
+
Use an alternative path for the TypeScript configuration file.
|
|
49
|
+
|
|
50
|
+
Using `-t jsconfig.json` is also supported.
|
|
51
|
+
|
|
52
|
+
Default location: `tsconfig.json`
|
|
53
|
+
|
|
54
|
+
### `knip-bun`
|
|
55
|
+
|
|
56
|
+
Run Knip using the Bun runtime (instead of Node.js + jiti).
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
knip-bun
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This is equal to `bunx --bun knip`
|
|
63
|
+
|
|
64
|
+
Requires [Bun][1] to be installed. Also see [known issues][2] for the type of
|
|
65
|
+
issues this might help with.
|
|
66
|
+
|
|
67
|
+
### NO_COLOR
|
|
68
|
+
|
|
69
|
+
The built-in reporters use the [NO_COLOR][3] friendly [picocolors][4]:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
NO_COLOR=1 knip
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Mode
|
|
76
|
+
|
|
77
|
+
### `--cache`
|
|
78
|
+
|
|
79
|
+
Enable caching.
|
|
80
|
+
|
|
81
|
+
Consecutive runs are 10-40% faster as the results of file analysis (AST
|
|
82
|
+
traversal) are cached. Conservative. Cache strategy based on file meta data
|
|
83
|
+
(modification time + file size).
|
|
84
|
+
|
|
85
|
+
### `--cache-location`
|
|
86
|
+
|
|
87
|
+
Provide alternative cache location.
|
|
88
|
+
|
|
89
|
+
Default location: `./node_modules/.cache/knip`
|
|
90
|
+
|
|
91
|
+
### `--include-entry-exports`
|
|
92
|
+
|
|
93
|
+
When a repository is self-contained or private, you may want to include entry
|
|
94
|
+
files when reporting unused exports:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
knip --include-entry-exports
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Also see [includeEntryExports][5].
|
|
101
|
+
|
|
102
|
+
### `--include-libs`
|
|
103
|
+
|
|
104
|
+
Getting false positives for exports consumed by external libraries? Try the
|
|
105
|
+
`--include-libs` flag:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
knip --include-libs
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Also see [external libs][6].
|
|
112
|
+
|
|
113
|
+
### `--isolate-workspaces`
|
|
114
|
+
|
|
115
|
+
By default, Knip optimizes performance using [workspace sharing][7] to existing
|
|
116
|
+
TypeScript programs, based on the compatibility of their `compilerOptions`. This
|
|
117
|
+
flag disables this behavior and creates one program per workspace, which is
|
|
118
|
+
slower but memory usage is spread more evenly over time.
|
|
119
|
+
|
|
120
|
+
### `--no-gitignore`
|
|
121
|
+
|
|
122
|
+
Ignore `.gitignore` files.
|
|
123
|
+
|
|
124
|
+
### `--production`
|
|
125
|
+
|
|
126
|
+
Lint only production source files. This excludes:
|
|
127
|
+
|
|
128
|
+
- entry files defined by plugins:
|
|
129
|
+
- test files
|
|
130
|
+
- configuration files
|
|
131
|
+
- Storybook stories
|
|
132
|
+
- `devDependencies` from `package.json`
|
|
133
|
+
|
|
134
|
+
Read more at [Production Mode][8].
|
|
135
|
+
|
|
136
|
+
### `--strict`
|
|
137
|
+
|
|
138
|
+
Isolate workspaces and consider only direct dependencies. Implies [production
|
|
139
|
+
mode][9].
|
|
140
|
+
|
|
141
|
+
Read more at [Production Mode][8].
|
|
142
|
+
|
|
143
|
+
### `--watch`
|
|
144
|
+
|
|
145
|
+
Watch current directory, and update reported issues when a file is modified,
|
|
146
|
+
added or deleted.
|
|
147
|
+
|
|
148
|
+
Watch mode focuses on imports and exports in source files. During watch mode,
|
|
149
|
+
changes in `package.json` or `node_modules` may not cause an updated report.
|
|
150
|
+
|
|
151
|
+
## Scope
|
|
152
|
+
|
|
153
|
+
### `--workspace [filter]`
|
|
154
|
+
|
|
155
|
+
Select one or multiple workspaces (including its ancestor and dependent
|
|
156
|
+
workspaces). The default behavior is to lint all configured workspaces.
|
|
157
|
+
|
|
158
|
+
Shortcut: `-W`
|
|
159
|
+
|
|
160
|
+
See [filter workspaces][10] for more details and examples.
|
|
161
|
+
|
|
162
|
+
### `--directory [dir]`
|
|
163
|
+
|
|
164
|
+
Default: `cwd` (current directory)
|
|
165
|
+
|
|
166
|
+
Run the process from a different directory.
|
|
167
|
+
|
|
168
|
+
### `--exclude`
|
|
169
|
+
|
|
170
|
+
Exclude provided issue types from report. Can be comma-separated or repeated.
|
|
171
|
+
|
|
172
|
+
Example:
|
|
173
|
+
|
|
174
|
+
```sh
|
|
175
|
+
knip --exclude classMembers,enumMembers
|
|
176
|
+
knip --exclude classMembers --exclude enumMembers
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `--include`
|
|
180
|
+
|
|
181
|
+
Report only provided issue types. Can be comma-separated or repeated.
|
|
182
|
+
|
|
183
|
+
Example:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
knip --include files,dependencies
|
|
187
|
+
knip --include files --include dependencies
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Available [issue types][11] when filtering output using `--include` or
|
|
191
|
+
`--exclude`:
|
|
192
|
+
|
|
193
|
+
- `files`
|
|
194
|
+
- `dependencies`
|
|
195
|
+
- `unlisted`
|
|
196
|
+
- `unresolved`
|
|
197
|
+
- `exports`
|
|
198
|
+
- `nsExports`
|
|
199
|
+
- `classMembers`
|
|
200
|
+
- `types`
|
|
201
|
+
- `nsTypes`
|
|
202
|
+
- `enumMembers`
|
|
203
|
+
- `duplicates`
|
|
204
|
+
- `catalog`
|
|
205
|
+
|
|
206
|
+
### `--dependencies`
|
|
207
|
+
|
|
208
|
+
Shortcut to include all types of dependency issues:
|
|
209
|
+
|
|
210
|
+
```sh
|
|
211
|
+
--include dependencies,unlisted,binaries,unresolved,catalog
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### `--exports`
|
|
215
|
+
|
|
216
|
+
Shortcut to include all types of export issues:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
--include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### `--files`
|
|
223
|
+
|
|
224
|
+
Shortcut to include file issues:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
--include files
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### `--tags`
|
|
231
|
+
|
|
232
|
+
Exports can be tagged with known or arbitrary JSDoc/TSDoc tags:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
/**
|
|
236
|
+
* Description of my exported value
|
|
237
|
+
*
|
|
238
|
+
* @type number
|
|
239
|
+
* @internal Important matters
|
|
240
|
+
* @lintignore
|
|
241
|
+
*/
|
|
242
|
+
export const myExport = 1;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
And then include (`+`) or exclude (`-`) these tagged exports from the report
|
|
246
|
+
like so:
|
|
247
|
+
|
|
248
|
+
```shell
|
|
249
|
+
knip --tags=-lintignore,-internal
|
|
250
|
+
knip --tags=+custom
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
This way, you can either focus on or ignore specific tagged exports with tags
|
|
254
|
+
you define yourself. This also works for individual class or enum members.
|
|
255
|
+
|
|
256
|
+
The default directive is `+` (include) and the `@` prefix is ignored, so the
|
|
257
|
+
notation below is valid and will report only exports tagged `@lintignore` or
|
|
258
|
+
`@internal`:
|
|
259
|
+
|
|
260
|
+
```shell
|
|
261
|
+
knip --tags @lintignore --tags @internal
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Fix
|
|
265
|
+
|
|
266
|
+
### `--fix`
|
|
267
|
+
|
|
268
|
+
Read more at [auto-fix][12].
|
|
269
|
+
|
|
270
|
+
### `--fix-type`
|
|
271
|
+
|
|
272
|
+
Fix only issues of type, can be comma-separated or repeated.
|
|
273
|
+
|
|
274
|
+
More info about fixable types at [issue types][11]
|
|
275
|
+
|
|
276
|
+
### `--allow-remove-files`
|
|
277
|
+
|
|
278
|
+
Allow Knip to remove files (with `--fix`).
|
|
279
|
+
|
|
280
|
+
### `--format`
|
|
281
|
+
|
|
282
|
+
Format modified files after `--fix` using the local formatter.
|
|
283
|
+
|
|
284
|
+
## Output
|
|
285
|
+
|
|
286
|
+
### `--preprocessor [preprocessor]`
|
|
287
|
+
|
|
288
|
+
Preprocess the results before providing it to the [reporter(s)][13].
|
|
289
|
+
|
|
290
|
+
Can be repeated. Examples:
|
|
291
|
+
|
|
292
|
+
```sh
|
|
293
|
+
knip --preprocessor ./my-preprocessor.ts
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
```sh
|
|
297
|
+
knip --preprocessor preprocessor-package
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Also see [Reporters & Preprocessors][14].
|
|
301
|
+
|
|
302
|
+
### `--preprocessor-options [json]`
|
|
303
|
+
|
|
304
|
+
Pass extra options to the preprocessor as JSON string.
|
|
305
|
+
|
|
306
|
+
```sh
|
|
307
|
+
knip --preprocessor ./preproc.ts --preprocessor-options '{"key":"value"}'
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### `--reporter [reporter]`
|
|
311
|
+
|
|
312
|
+
Available reporters:
|
|
313
|
+
|
|
314
|
+
- `symbols` (default)
|
|
315
|
+
- `compact`
|
|
316
|
+
- `codeowners`
|
|
317
|
+
- `json`
|
|
318
|
+
- `codeclimate`
|
|
319
|
+
- `markdown`
|
|
320
|
+
- `disclosure`
|
|
321
|
+
- `github-actions`
|
|
322
|
+
|
|
323
|
+
Can be repeated. Example:
|
|
324
|
+
|
|
325
|
+
```sh
|
|
326
|
+
knip --reporter compact
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Also see [Reporters & Preprocessors][14].
|
|
330
|
+
|
|
331
|
+
### `--reporter-options [json]`
|
|
332
|
+
|
|
333
|
+
Pass extra options to the reporter (as JSON string):
|
|
334
|
+
|
|
335
|
+
Example:
|
|
336
|
+
|
|
337
|
+
```sh
|
|
338
|
+
knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### `--no-config-hints`
|
|
342
|
+
|
|
343
|
+
Suppress configuration hints.
|
|
344
|
+
|
|
345
|
+
### `--treat-config-hints-as-errors`
|
|
346
|
+
|
|
347
|
+
Exit with non-zero exit code (`1`) if there are any configuration hints.
|
|
348
|
+
|
|
349
|
+
### `--max-issues`
|
|
350
|
+
|
|
351
|
+
Maximum number of issues before non-zero exit code. Default: `0`
|
|
352
|
+
|
|
353
|
+
### `--max-show-issues`
|
|
354
|
+
|
|
355
|
+
Maximum number of issues per type to display (does not affect exit code).
|
|
356
|
+
|
|
357
|
+
### `--no-exit-code`
|
|
358
|
+
|
|
359
|
+
Always exit with code zero (`0`), even when there are lint issues.
|
|
360
|
+
|
|
361
|
+
The default exit codes:
|
|
362
|
+
|
|
363
|
+
| Code | Description |
|
|
364
|
+
| :--: | :--------------------------------------------------------------- |
|
|
365
|
+
| `0` | Knip ran successfully, no lint issues |
|
|
366
|
+
| `1` | Knip ran successfully, but there is at least one lint issue |
|
|
367
|
+
| `2` | Knip did not run successfully due to bad input or internal error |
|
|
368
|
+
|
|
369
|
+
## Troubleshooting
|
|
370
|
+
|
|
371
|
+
### `--debug`
|
|
372
|
+
|
|
373
|
+
Shortcut: `-d`
|
|
374
|
+
|
|
375
|
+
Show [debug output][15].
|
|
376
|
+
|
|
377
|
+
### `--memory`
|
|
378
|
+
|
|
379
|
+
```txt frame=terminal
|
|
380
|
+
knip --memory
|
|
381
|
+
|
|
382
|
+
(results)
|
|
383
|
+
|
|
384
|
+
# heapUsed heapTotal freemem
|
|
385
|
+
-- -------- --------- -------
|
|
386
|
+
0 42.09 70.91 2251.00
|
|
387
|
+
1 927.04 1042.58 1166.47
|
|
388
|
+
2 973.29 1047.33 1160.92
|
|
389
|
+
3 971.54 1079.83 1121.66
|
|
390
|
+
4 997.80 1080.33 1120.34
|
|
391
|
+
5 1001.88 1098.08 1100.72
|
|
392
|
+
6 1038.69 1116.58 1100.72
|
|
393
|
+
7 1082.12 1166.33 1100.72
|
|
394
|
+
8 1145.46 1224.50 1100.72
|
|
395
|
+
9 1115.82 1240.25 1100.72
|
|
396
|
+
10 1182.35 1249.75 973.05
|
|
397
|
+
11 637.32 1029.17 943.63
|
|
398
|
+
12 674.30 1029.33 943.39
|
|
399
|
+
13 682.24 1029.33 941.63
|
|
400
|
+
14 707.70 1029.33 937.48
|
|
401
|
+
|
|
402
|
+
Total running time: 4.3s
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Can be used with [--isolate-workspaces][16] to see the difference in garbage
|
|
406
|
+
collection during the process.
|
|
407
|
+
|
|
408
|
+
### `--memory-realtime`
|
|
409
|
+
|
|
410
|
+
Use this if Knip crashes to still see memory usage info over time:
|
|
411
|
+
|
|
412
|
+
```txt frame=terminal
|
|
413
|
+
knip --memory-realtime
|
|
414
|
+
|
|
415
|
+
# heapUsed heapTotal freemem
|
|
416
|
+
- -------- --------- -------
|
|
417
|
+
0 42.09 70.91 2251.00
|
|
418
|
+
1 927.04 1042.58 1166.47
|
|
419
|
+
...mem info keeps being logged...
|
|
420
|
+
|
|
421
|
+
(results)
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### `--performance`
|
|
425
|
+
|
|
426
|
+
Use this flag to get the count and execution time of potentially expensive
|
|
427
|
+
functions in a table. Example:
|
|
428
|
+
|
|
429
|
+
```txt frame=terminal
|
|
430
|
+
$ knip --performance
|
|
431
|
+
|
|
432
|
+
(results)
|
|
433
|
+
|
|
434
|
+
Name size min max median sum
|
|
435
|
+
----------------------------- ---- -------- -------- -------- --------
|
|
436
|
+
findReferences 648 84.98 7698.61 96.41 70941.70
|
|
437
|
+
createProgram 2 6295.84 7064.68 6680.26 13360.52
|
|
438
|
+
glob 6 0.05 995.78 513.82 3150.87
|
|
439
|
+
findESLintDependencies 2 0.01 74.41 37.21 74.41
|
|
440
|
+
findGithubActionsDependencies 6 0.16 12.71 0.65 23.45
|
|
441
|
+
findBabelDependencies 2 0.00 38.75 19.37 38.75
|
|
442
|
+
...
|
|
443
|
+
|
|
444
|
+
Total running time: 5s
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
- `name`: the internal Knip function name
|
|
448
|
+
- `size`: number of function invocations
|
|
449
|
+
- `min`: the fastest invocation
|
|
450
|
+
- `max`: the slowest invocation
|
|
451
|
+
- `median`: the median invocation
|
|
452
|
+
- `sum` the accumulated time of all invocations
|
|
453
|
+
|
|
454
|
+
This is not yet available in Bun, since it does not support
|
|
455
|
+
`performance.timerify` ([GitHub issue][17]).
|
|
456
|
+
|
|
457
|
+
### `--performance-fn`
|
|
458
|
+
|
|
459
|
+
Limit the output of `--performance` to a single function to minimize the
|
|
460
|
+
overhead of the `timerify` Node.js built-in and focus on that function alone:
|
|
461
|
+
|
|
462
|
+
```txt frame=terminal
|
|
463
|
+
$ knip --performance-fn resolveSync
|
|
464
|
+
|
|
465
|
+
(results)
|
|
466
|
+
|
|
467
|
+
Name size min max median sum
|
|
468
|
+
----------- ----- ---- ---- ------ ------
|
|
469
|
+
resolveSync 66176 0.00 5.69 0.00 204.85
|
|
470
|
+
|
|
471
|
+
Total running time: 12.9s
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### `--trace`
|
|
475
|
+
|
|
476
|
+
Trace exports to see where they are imported.
|
|
477
|
+
|
|
478
|
+
Also see [Trace][18].
|
|
479
|
+
|
|
480
|
+
### `--trace-dependency [name]`
|
|
481
|
+
|
|
482
|
+
Trace package or binary name to see where it's referenced. Implies
|
|
483
|
+
[--trace][19].
|
|
484
|
+
|
|
485
|
+
### `--trace-export [name]`
|
|
486
|
+
|
|
487
|
+
Trace export name to see where it's imported. Implies [--trace][19].
|
|
488
|
+
|
|
489
|
+
### `--trace-file [path]`
|
|
490
|
+
|
|
491
|
+
Trace file to see where its exports are imported. Implies [--trace][19].
|
|
492
|
+
|
|
493
|
+
[1]: https://bun.sh
|
|
494
|
+
[2]: ../reference/known-issues.md
|
|
495
|
+
[3]: https://no-color.org/
|
|
496
|
+
[4]: https://www.npmjs.com/package/picocolors
|
|
497
|
+
[5]: ./configuration.md#includeentryexports
|
|
498
|
+
[6]: ../guides/handling-issues.mdx#external-libraries
|
|
499
|
+
[7]: ../guides/performance.md#workspace-sharing
|
|
500
|
+
[8]: ../features/production-mode.md
|
|
501
|
+
[9]: #--production
|
|
502
|
+
[10]: ../features/monorepos-and-workspaces.md#filter-workspaces
|
|
503
|
+
[11]: ./issue-types.md
|
|
504
|
+
[12]: ../features/auto-fix.mdx
|
|
505
|
+
[13]: #--reporter-reporter
|
|
506
|
+
[14]: ../features/reporters.md
|
|
507
|
+
[15]: ../guides/troubleshooting.md#debug
|
|
508
|
+
[16]: #--isolate-workspaces
|
|
509
|
+
[17]: https://github.com/oven-sh/bun/issues/9271
|
|
510
|
+
[18]: ../guides/troubleshooting.md#trace
|
|
511
|
+
[19]: #--trace
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Configuration Hints
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Knip emits configuration hints to help keep your configuration file tidy and
|
|
6
|
+
reduce drift.
|
|
7
|
+
|
|
8
|
+
They're warnings by default, not lint findings. But addressing the hints might
|
|
9
|
+
improve results significantly. The hints on this page are sorted by
|
|
10
|
+
impact/importance (most impactful first).
|
|
11
|
+
|
|
12
|
+
Use [`--treat-config-hints-as-errors`][1] or [`treatConfigHintsAsErrors`][2] to
|
|
13
|
+
make any configuration hint result in a non-zero exit code and fail CI.
|
|
14
|
+
|
|
15
|
+
## Unconfigured projects
|
|
16
|
+
|
|
17
|
+
Too many unused files in a single workspace-codebase, caused by a missing
|
|
18
|
+
configuration file or incomplete configuration:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
Create knip.json configuration file, and add entry and/or refine project files (42 unused files)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or if you have a config file:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Add entry and/or refine project files (42 unused files)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Solution**: Add and refine `entry` and/or `project` patterns.
|
|
31
|
+
|
|
32
|
+
Related resources:
|
|
33
|
+
|
|
34
|
+
- [Configuration][3]
|
|
35
|
+
- [Monorepos & Workspaces][4]
|
|
36
|
+
|
|
37
|
+
## Unconfigured workspaces
|
|
38
|
+
|
|
39
|
+
Too many unused files in a monorepo, caused by a missing configuration file or
|
|
40
|
+
incomplete configuration:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Create knip.json configuration file with workspaces["packages/app"] object (42 unused files)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or if you have a config file:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
Add entry and/or refine project files in workspaces["packages/app"] (42 unused files)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Solution**: add a `workspaces` object to configuration. Add and refine `entry`
|
|
53
|
+
and/or `project` patterns. For instance, the example message translates to
|
|
54
|
+
configuration like this:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"workspaces" {
|
|
59
|
+
"packages/app": {
|
|
60
|
+
"entry": ["src/App.tsx"],
|
|
61
|
+
"project": ["src/**/*.ts"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Related resources:
|
|
68
|
+
|
|
69
|
+
- [Configuring Project Files][5]
|
|
70
|
+
- [Monorepos & Workspaces][4]
|
|
71
|
+
|
|
72
|
+
## Top-level entry/project
|
|
73
|
+
|
|
74
|
+
In monorepos, Knip uses only `entry` and `project` under `workspaces`. The
|
|
75
|
+
top-level keys with the same name are ignored.
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
Remove, or move unused top-level entry to one of "workspaces"
|
|
79
|
+
Remove, or move unused top-level project to one of "workspaces"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Solution**: Remove top-level `entry` and `project` keys, use these options in
|
|
83
|
+
`workspaces` instead.
|
|
84
|
+
|
|
85
|
+
```jsonc
|
|
86
|
+
{
|
|
87
|
+
"entry": ["src/App.tsx"], // move entry/project from here... ↴
|
|
88
|
+
"project": ["src/**/*.ts"],
|
|
89
|
+
"workspaces": {
|
|
90
|
+
".": {
|
|
91
|
+
"entry": ["src/App.tsx"], // ...to the correct workspace(s) ↲
|
|
92
|
+
"project": ["src/**/*.ts"],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Unused entry in ignore group
|
|
99
|
+
|
|
100
|
+
An entry of an ignore list is no longer needed, remove it.
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
Remove from ignoreWorkspaces
|
|
104
|
+
Remove from ignoreDependencies
|
|
105
|
+
Remove from ignoreBinaries
|
|
106
|
+
Remove from ignoreUnresolved
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Solution**: Remove the entry from the array.
|
|
110
|
+
|
|
111
|
+
## Useless patterns
|
|
112
|
+
|
|
113
|
+
A glob pattern in `entry` or `project` does not match any files.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Refine entry pattern (no matches)
|
|
117
|
+
Refine project pattern (no matches)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Solution**: Refine or remove the `entry` or `project` entry.
|
|
121
|
+
|
|
122
|
+
## Redundant patterns
|
|
123
|
+
|
|
124
|
+
A glob/pattern is redundant, because it's already covered by defaults or added
|
|
125
|
+
by an enabled plugin.
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
Remove redundant entry pattern
|
|
129
|
+
Remove redundant project pattern
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Solution**: Remove the `entry` or `project` entry.
|
|
133
|
+
|
|
134
|
+
## Missing package entry file
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
Package entry file not found
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Solution**: Refine or remove the entry in `package.json`.
|
|
141
|
+
|
|
142
|
+
[1]: ./cli.md#--treat-config-hints-as-errors
|
|
143
|
+
[2]: ./configuration.md#treatconfighintsaserrors
|
|
144
|
+
[3]: ../overview/configuration.md
|
|
145
|
+
[4]: ../features/monorepos-and-workspaces.md
|
|
146
|
+
[5]: ../guides/configuring-project-files.md
|