knip 1.14.2 → 1.14.3
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 +109 -93
- package/dist/constants.js +5 -1
- package/dist/plugins/jest/index.d.ts +1 -1
- package/dist/plugins/jest/index.js +1 -1
- package/dist/plugins/mocha/index.d.ts +1 -1
- package/dist/plugins/mocha/index.js +1 -1
- package/dist/plugins/playwright/index.js +1 -1
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,13 +35,19 @@ with OpenAI_</sup>
|
|
|
35
35
|
|
|
36
36
|
When coming from version v0.13.3 or before, please see [migration to v1][7].
|
|
37
37
|
|
|
38
|
+
## Announcement: Knip v2
|
|
39
|
+
|
|
40
|
+
The next major release is upcoming. Please see [https://github.com/webpro/knip/issues/73][8] for the full story. Use
|
|
41
|
+
`npm install knip@next` to try it out if you're curious! No changes in configuration necessary. Find the updated
|
|
42
|
+
documentation at [https://github.com/webpro/knip/blob/v2/README.md][9].
|
|
43
|
+
|
|
38
44
|
## Issues
|
|
39
45
|
|
|
40
|
-
Are you seeing false positives? Please report them by [opening an issue in this repo][
|
|
46
|
+
Are you seeing false positives? Please report them by [opening an issue in this repo][10]. Bonus points for linking to a
|
|
41
47
|
public repository using Knip, or even opening a pull request with a directory and example files in `test/fixtures`.
|
|
42
48
|
Correctness and bug fixes have priority over performance and new features.
|
|
43
49
|
|
|
44
|
-
Also see the [FAQ][
|
|
50
|
+
Also see the [FAQ][11].
|
|
45
51
|
|
|
46
52
|
## Installation
|
|
47
53
|
|
|
@@ -190,7 +196,7 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
190
196
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
191
197
|
|
|
192
198
|
Still not happy with the results? Getting too much output/false positives? The [FAQ][9] may be useful. Feel free to open
|
|
193
|
-
an issue and I'm happy to look into it. Also see the next section on how to [ignore][
|
|
199
|
+
an issue and I'm happy to look into it. Also see the next section on how to [ignore][12] certain false positives:
|
|
194
200
|
|
|
195
201
|
## Ignore
|
|
196
202
|
|
|
@@ -265,38 +271,38 @@ Here's some example output when running Knip in a workspace:
|
|
|
265
271
|
|
|
266
272
|
Knip contains a growing list of plugins:
|
|
267
273
|
|
|
268
|
-
- [Babel][
|
|
269
|
-
- [Capacitor][
|
|
270
|
-
- [Changesets][
|
|
271
|
-
- [commitlint][
|
|
272
|
-
- [Cypress][
|
|
273
|
-
- [ESLint][
|
|
274
|
-
- [Gatsby][
|
|
275
|
-
- [GitHub Actions][
|
|
276
|
-
- [husky][
|
|
277
|
-
- [Jest][
|
|
278
|
-
- [Lefthook][
|
|
279
|
-
- [lint-staged][
|
|
280
|
-
- [markdownlint][
|
|
281
|
-
- [Mocha][
|
|
282
|
-
- [Next.js][
|
|
283
|
-
- [npm-package-json-lint][
|
|
284
|
-
- [Nx][
|
|
285
|
-
- [nyc][
|
|
286
|
-
- [Playwright][
|
|
287
|
-
- [PostCSS][
|
|
288
|
-
- [Prettier][
|
|
289
|
-
- [Release It][
|
|
290
|
-
- [Remark][
|
|
291
|
-
- [Remix][
|
|
292
|
-
- [Rollup][
|
|
293
|
-
- [Sentry][
|
|
294
|
-
- [Storybook][
|
|
295
|
-
- [Stryker][
|
|
296
|
-
- [TypeDoc][
|
|
297
|
-
- [TypeScript][
|
|
298
|
-
- [Vitest][
|
|
299
|
-
- [Webpack][
|
|
274
|
+
- [Babel][13]
|
|
275
|
+
- [Capacitor][14]
|
|
276
|
+
- [Changesets][15]
|
|
277
|
+
- [commitlint][16]
|
|
278
|
+
- [Cypress][17]
|
|
279
|
+
- [ESLint][18]
|
|
280
|
+
- [Gatsby][19]
|
|
281
|
+
- [GitHub Actions][20]
|
|
282
|
+
- [husky][21]
|
|
283
|
+
- [Jest][22]
|
|
284
|
+
- [Lefthook][23]
|
|
285
|
+
- [lint-staged][24]
|
|
286
|
+
- [markdownlint][25]
|
|
287
|
+
- [Mocha][26]
|
|
288
|
+
- [Next.js][27]
|
|
289
|
+
- [npm-package-json-lint][28]
|
|
290
|
+
- [Nx][29]
|
|
291
|
+
- [nyc][30]
|
|
292
|
+
- [Playwright][31]
|
|
293
|
+
- [PostCSS][32]
|
|
294
|
+
- [Prettier][33]
|
|
295
|
+
- [Release It][34]
|
|
296
|
+
- [Remark][35]
|
|
297
|
+
- [Remix][36]
|
|
298
|
+
- [Rollup][37]
|
|
299
|
+
- [Sentry][38]
|
|
300
|
+
- [Storybook][39]
|
|
301
|
+
- [Stryker][40]
|
|
302
|
+
- [TypeDoc][41]
|
|
303
|
+
- [TypeScript][42]
|
|
304
|
+
- [Vitest][43]
|
|
305
|
+
- [Webpack][44]
|
|
300
306
|
|
|
301
307
|
Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
|
|
302
308
|
whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
|
|
@@ -304,7 +310,7 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
|
|
|
304
310
|
|
|
305
311
|
Most plugins use one or both of the following file types:
|
|
306
312
|
|
|
307
|
-
- `config` - custom dependency resolvers are applied to the [config files][
|
|
313
|
+
- `config` - custom dependency resolvers are applied to the [config files][45]
|
|
308
314
|
- `entry` - files to include with the analysis of the rest of the source code
|
|
309
315
|
|
|
310
316
|
See each plugin's documentation for its default values.
|
|
@@ -329,6 +335,13 @@ rest to find which of those dependencies are unused or missing.
|
|
|
329
335
|
Other configuration files use `require` or `import` statements to use dependencies, so they can be analyzed like the
|
|
330
336
|
rest of the source files. These configuration files are also considered `entry` files.
|
|
331
337
|
|
|
338
|
+
For plugins related to test files, it's good to know that the following glob patterns are always included by default
|
|
339
|
+
(see [TEST_FILE_PATTERNS in constants.ts][46]):
|
|
340
|
+
|
|
341
|
+
- `**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}`
|
|
342
|
+
- `**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs}`
|
|
343
|
+
- `test/**/*.{js,jsx,ts,tsx,mjs,cjs}`
|
|
344
|
+
|
|
332
345
|
### Disable a plugin
|
|
333
346
|
|
|
334
347
|
In case a plugin causes issues, it can be disabled by using `false` as its value (e.g. `"webpack": false`).
|
|
@@ -405,10 +418,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
|
|
|
405
418
|
|
|
406
419
|
Knip provides the following built-in reporters:
|
|
407
420
|
|
|
408
|
-
- [`codeowners`][
|
|
409
|
-
- [`compact`][
|
|
410
|
-
- [`json`][
|
|
411
|
-
- [`symbol`][
|
|
421
|
+
- [`codeowners`][47]
|
|
422
|
+
- [`compact`][48]
|
|
423
|
+
- [`json`][49]
|
|
424
|
+
- [`symbol`][50] (default)
|
|
412
425
|
|
|
413
426
|
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
414
427
|
|
|
@@ -435,7 +448,7 @@ type ReporterOptions = {
|
|
|
435
448
|
|
|
436
449
|
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
437
450
|
|
|
438
|
-
Find more details and ideas in [custom reporters][
|
|
451
|
+
Find more details and ideas in [custom reporters][51].
|
|
439
452
|
|
|
440
453
|
## Libraries and "unused" exports
|
|
441
454
|
|
|
@@ -493,7 +506,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
|
|
|
493
506
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
494
507
|
to match the custom location(s).
|
|
495
508
|
|
|
496
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
509
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][52].
|
|
497
510
|
|
|
498
511
|
#### Too many unused exports
|
|
499
512
|
|
|
@@ -501,7 +514,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
501
514
|
|
|
502
515
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
503
516
|
add the containing file to the `entry` array in the configuration.
|
|
504
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
517
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][53].
|
|
505
518
|
|
|
506
519
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
507
520
|
|
|
@@ -521,7 +534,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
521
534
|
|
|
522
535
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
523
536
|
|
|
524
|
-
| Feature | **knip** | [depcheck][
|
|
537
|
+
| Feature | **knip** | [depcheck][54] | [unimported][55] | [ts-unused-exports][56] | [ts-prune][57] |
|
|
525
538
|
| :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
526
539
|
| Unused files | ✅ | - | ✅ | - | - |
|
|
527
540
|
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
@@ -556,7 +569,7 @@ The following commands are similar:
|
|
|
556
569
|
unimported
|
|
557
570
|
knip --production --dependencies --include files
|
|
558
571
|
|
|
559
|
-
Also see [production mode][
|
|
572
|
+
Also see [production mode][58].
|
|
560
573
|
|
|
561
574
|
### ts-unused-exports
|
|
562
575
|
|
|
@@ -593,51 +606,54 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
593
606
|
[5]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
594
607
|
[6]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
595
608
|
[7]: ./docs/migration-to-v1.md
|
|
596
|
-
[8]: https://github.com/webpro/knip/issues
|
|
597
|
-
[9]:
|
|
598
|
-
[10]:
|
|
599
|
-
[11]:
|
|
600
|
-
[12]:
|
|
601
|
-
[13]: ./src/plugins/
|
|
602
|
-
[14]: ./src/plugins/
|
|
603
|
-
[15]: ./src/plugins/
|
|
604
|
-
[16]: ./src/plugins/
|
|
605
|
-
[17]: ./src/plugins/
|
|
606
|
-
[18]: ./src/plugins/
|
|
607
|
-
[19]: ./src/plugins/
|
|
608
|
-
[20]: ./src/plugins/
|
|
609
|
-
[21]: ./src/plugins/
|
|
610
|
-
[22]: ./src/plugins/
|
|
611
|
-
[23]: ./src/plugins/
|
|
612
|
-
[24]: ./src/plugins/
|
|
613
|
-
[25]: ./src/plugins/
|
|
614
|
-
[26]: ./src/plugins/
|
|
615
|
-
[27]: ./src/plugins/
|
|
616
|
-
[28]: ./src/plugins/
|
|
617
|
-
[29]: ./src/plugins/
|
|
618
|
-
[30]: ./src/plugins/
|
|
619
|
-
[31]: ./src/plugins/
|
|
620
|
-
[32]: ./src/plugins/
|
|
621
|
-
[33]: ./src/plugins/
|
|
622
|
-
[34]: ./src/plugins/
|
|
623
|
-
[35]: ./src/plugins/
|
|
624
|
-
[36]: ./src/plugins/
|
|
625
|
-
[37]: ./src/plugins/
|
|
626
|
-
[38]: ./src/plugins/
|
|
627
|
-
[39]: ./src/plugins/
|
|
628
|
-
[40]: ./src/plugins/
|
|
629
|
-
[41]: ./src/plugins/
|
|
630
|
-
[42]: ./src/plugins/
|
|
631
|
-
[43]:
|
|
632
|
-
[44]:
|
|
633
|
-
[45]: #
|
|
634
|
-
[46]:
|
|
635
|
-
[47]: #
|
|
636
|
-
[48]:
|
|
637
|
-
[49]: #
|
|
638
|
-
[50]: #
|
|
639
|
-
[51]:
|
|
640
|
-
[52]:
|
|
641
|
-
[53]:
|
|
642
|
-
[54]: https://github.com/
|
|
643
|
-
[55]:
|
|
609
|
+
[8]: https://github.com/webpro/knip/issues/73
|
|
610
|
+
[9]: https://github.com/webpro/knip/blob/v2/README.md
|
|
611
|
+
[10]: https://github.com/webpro/knip/issues
|
|
612
|
+
[11]: #faq
|
|
613
|
+
[12]: #ignore
|
|
614
|
+
[13]: ./src/plugins/babel
|
|
615
|
+
[14]: ./src/plugins/capacitor
|
|
616
|
+
[15]: ./src/plugins/changesets
|
|
617
|
+
[16]: ./src/plugins/commitlint
|
|
618
|
+
[17]: ./src/plugins/cypress
|
|
619
|
+
[18]: ./src/plugins/eslint
|
|
620
|
+
[19]: ./src/plugins/gatsby
|
|
621
|
+
[20]: ./src/plugins/github-actions
|
|
622
|
+
[21]: ./src/plugins/husky
|
|
623
|
+
[22]: ./src/plugins/jest
|
|
624
|
+
[23]: ./src/plugins/lefthook
|
|
625
|
+
[24]: ./src/plugins/lint-staged
|
|
626
|
+
[25]: ./src/plugins/markdownlint
|
|
627
|
+
[26]: ./src/plugins/mocha
|
|
628
|
+
[27]: ./src/plugins/next
|
|
629
|
+
[28]: ./src/plugins/npm-package-json-lint
|
|
630
|
+
[29]: ./src/plugins/nx
|
|
631
|
+
[30]: ./src/plugins/nyc
|
|
632
|
+
[31]: ./src/plugins/playwright
|
|
633
|
+
[32]: ./src/plugins/postcss
|
|
634
|
+
[33]: ./src/plugins/prettier
|
|
635
|
+
[34]: ./src/plugins/release-it
|
|
636
|
+
[35]: ./src/plugins/remark
|
|
637
|
+
[36]: ./src/plugins/remix
|
|
638
|
+
[37]: ./src/plugins/rollup
|
|
639
|
+
[38]: ./src/plugins/sentry
|
|
640
|
+
[39]: ./src/plugins/storybook
|
|
641
|
+
[40]: ./src/plugins/stryker
|
|
642
|
+
[41]: ./src/plugins/typedoc
|
|
643
|
+
[42]: ./src/plugins/typescript
|
|
644
|
+
[43]: ./src/plugins/vitest
|
|
645
|
+
[44]: ./src/plugins/webpack
|
|
646
|
+
[45]: #config
|
|
647
|
+
[46]: https://github.com/webpro/knip/blob/main/src/constants.ts
|
|
648
|
+
[47]: #code-owners
|
|
649
|
+
[48]: #compact
|
|
650
|
+
[49]: #json
|
|
651
|
+
[50]: #symbol-default
|
|
652
|
+
[51]: ./docs/custom-reporters.md
|
|
653
|
+
[52]: #create-a-new-plugin
|
|
654
|
+
[53]: #libraries-and-unused-exports
|
|
655
|
+
[54]: https://github.com/depcheck/depcheck
|
|
656
|
+
[55]: https://github.com/smeijer/unimported
|
|
657
|
+
[56]: https://github.com/pzavolinsky/ts-unused-exports
|
|
658
|
+
[57]: https://github.com/nadeesha/ts-prune
|
|
659
|
+
[58]: #production-mode
|
package/dist/constants.js
CHANGED
|
@@ -8,7 +8,11 @@ export const DEFAULT_WORKSPACE_CONFIG = {
|
|
|
8
8
|
paths: {},
|
|
9
9
|
ignore: [],
|
|
10
10
|
};
|
|
11
|
-
export const TEST_FILE_PATTERNS = [
|
|
11
|
+
export const TEST_FILE_PATTERNS = [
|
|
12
|
+
'**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}',
|
|
13
|
+
'**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs}',
|
|
14
|
+
'test/**/*.{js,jsx,ts,tsx,mjs,cjs}',
|
|
15
|
+
];
|
|
12
16
|
export const IGNORED_GLOBAL_BINARIES = [
|
|
13
17
|
'bun',
|
|
14
18
|
'deno',
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Jest";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -9,7 +9,7 @@ export const NAME = 'Jest';
|
|
|
9
9
|
export const ENABLERS = ['jest'];
|
|
10
10
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
11
11
|
export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}'];
|
|
12
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
12
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
13
13
|
const join = (base, id) => (isAbsolute(id) ? id : path.join(path.dirname(base), id));
|
|
14
14
|
const resolveExtensibleConfig = async (configFilePath) => {
|
|
15
15
|
const config = await _load(configFilePath);
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Mocha";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -6,7 +6,7 @@ export const NAME = 'Mocha';
|
|
|
6
6
|
export const ENABLERS = ['mocha'];
|
|
7
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
8
|
export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
|
|
9
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
9
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
10
10
|
const findMochaDependencies = async (configFilePath, { manifest }) => {
|
|
11
11
|
const config = configFilePath.endsWith('package.json') ? manifest.mocha : await _load(configFilePath);
|
|
12
12
|
if (config) {
|
|
@@ -2,4 +2,4 @@ import { hasDependency } from '../../util/plugin.js';
|
|
|
2
2
|
export const NAME = 'Playwright';
|
|
3
3
|
export const ENABLERS = ['@playwright/test'];
|
|
4
4
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
5
|
-
export const ENTRY_FILE_PATTERNS = ['playwright.config.{js,ts}'
|
|
5
|
+
export const ENTRY_FILE_PATTERNS = ['playwright.config.{js,ts}'];
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Vitest";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -7,7 +7,7 @@ export const NAME = 'Vitest';
|
|
|
7
7
|
export const ENABLERS = ['vitest'];
|
|
8
8
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
9
9
|
export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vite.config.ts'];
|
|
10
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
10
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
11
11
|
const findVitestDependencies = async (configFilePath) => {
|
|
12
12
|
const config = await _load(configFilePath);
|
|
13
13
|
if (!config || !config.test)
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.14.
|
|
1
|
+
export declare const version = "1.14.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.14.
|
|
1
|
+
export const version = '1.14.3';
|
package/package.json
CHANGED