knip 1.15.0 → 1.17.0
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 +119 -107
- package/dist/configuration-validator.d.ts +392 -0
- package/dist/configuration-validator.js +7 -0
- package/dist/plugins/ava/index.d.ts +6 -0
- package/dist/plugins/ava/index.js +22 -0
- package/dist/plugins/ava/types.d.ts +4 -0
- package/dist/plugins/ava/types.js +1 -0
- package/dist/plugins/commitizen/index.d.ts +6 -0
- package/dist/plugins/commitizen/index.js +15 -0
- package/dist/plugins/commitizen/types.d.ts +3 -0
- package/dist/plugins/commitizen/types.js +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/semantic-release/index.d.ts +6 -0
- package/dist/plugins/semantic-release/index.js +18 -0
- package/dist/plugins/semantic-release/types.d.ts +3 -0
- package/dist/plugins/semantic-release/types.js +1 -0
- package/dist/plugins/tailwind/index.d.ts +5 -0
- package/dist/plugins/tailwind/index.js +5 -0
- package/dist/util/fs.d.ts +4 -0
- package/dist/util/fs.js +17 -2
- package/dist/util/loader.js +7 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace-worker.d.ts +1 -1
- package/package.json +11 -11
- package/schema.json +16 -0
package/README.md
CHANGED
|
@@ -271,39 +271,43 @@ Here's some example output when running Knip in a workspace:
|
|
|
271
271
|
|
|
272
272
|
Knip contains a growing list of plugins:
|
|
273
273
|
|
|
274
|
-
- [
|
|
275
|
-
- [
|
|
276
|
-
- [
|
|
277
|
-
- [
|
|
278
|
-
- [
|
|
279
|
-
- [
|
|
280
|
-
- [
|
|
281
|
-
- [
|
|
282
|
-
- [
|
|
283
|
-
- [
|
|
284
|
-
- [
|
|
285
|
-
- [
|
|
286
|
-
- [
|
|
287
|
-
- [
|
|
288
|
-
- [
|
|
289
|
-
- [
|
|
290
|
-
- [
|
|
291
|
-
- [
|
|
292
|
-
- [
|
|
293
|
-
- [
|
|
294
|
-
- [
|
|
295
|
-
- [
|
|
296
|
-
- [
|
|
297
|
-
- [
|
|
298
|
-
- [
|
|
299
|
-
- [
|
|
300
|
-
- [
|
|
301
|
-
- [
|
|
302
|
-
- [
|
|
303
|
-
- [
|
|
304
|
-
- [
|
|
305
|
-
- [
|
|
306
|
-
- [
|
|
274
|
+
- [Ava][plugin-ava]
|
|
275
|
+
- [Babel][plugin-babel]
|
|
276
|
+
- [Capacitor][plugin-capacitor]
|
|
277
|
+
- [Changesets][plugin-changesets]
|
|
278
|
+
- [Commitizen][plugin-commitizen]
|
|
279
|
+
- [commitlint][plugin-commitlint]
|
|
280
|
+
- [cspell][plugin-cspell]
|
|
281
|
+
- [Cypress][plugin-cypress]
|
|
282
|
+
- [ESLint][plugin-eslint]
|
|
283
|
+
- [Gatsby][plugin-gatsby]
|
|
284
|
+
- [GitHub Actions][plugin-github-actions]
|
|
285
|
+
- [husky][plugin-husky]
|
|
286
|
+
- [Jest][plugin-jest]
|
|
287
|
+
- [Lefthook][plugin-lefthook]
|
|
288
|
+
- [lint-staged][plugin-lint-staged]
|
|
289
|
+
- [markdownlint][plugin-markdownlint]
|
|
290
|
+
- [Mocha][plugin-mocha]
|
|
291
|
+
- [Next.js][plugin-next]
|
|
292
|
+
- [npm-package-json-lint][plugin-npm-package-json-lint]
|
|
293
|
+
- [Nx][plugin-nx]
|
|
294
|
+
- [nyc][plugin-nyc]
|
|
295
|
+
- [Playwright][plugin-playwright]
|
|
296
|
+
- [PostCSS][plugin-postcss]
|
|
297
|
+
- [Prettier][plugin-prettier]
|
|
298
|
+
- [Release It][plugin-release-it]
|
|
299
|
+
- [Remark][plugin-remark]
|
|
300
|
+
- [Remix][plugin-remix]
|
|
301
|
+
- [Rollup][plugin-rollup]
|
|
302
|
+
- [Semantic Release][plugin-semantic-release]
|
|
303
|
+
- [Sentry][plugin-sentry]
|
|
304
|
+
- [Storybook][plugin-storybook]
|
|
305
|
+
- [Stryker][plugin-stryker]
|
|
306
|
+
- [Tailwind][plugin-tailwind]
|
|
307
|
+
- [TypeDoc][plugin-typedoc]
|
|
308
|
+
- [TypeScript][plugin-typescript]
|
|
309
|
+
- [Vitest][plugin-vitest]
|
|
310
|
+
- [Webpack][plugin-webpack]
|
|
307
311
|
|
|
308
312
|
Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
|
|
309
313
|
whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
|
|
@@ -311,7 +315,7 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
|
|
|
311
315
|
|
|
312
316
|
Most plugins use one or both of the following file types:
|
|
313
317
|
|
|
314
|
-
- `config` - custom dependency resolvers are applied to the [config files][
|
|
318
|
+
- `config` - custom dependency resolvers are applied to the [config files][13]
|
|
315
319
|
- `entry` - files to include with the analysis of the rest of the source code
|
|
316
320
|
|
|
317
321
|
See each plugin's documentation for its default values.
|
|
@@ -337,7 +341,7 @@ Other configuration files use `require` or `import` statements to use dependenci
|
|
|
337
341
|
rest of the source files. These configuration files are also considered `entry` files.
|
|
338
342
|
|
|
339
343
|
For plugins related to test files, it's good to know that the following glob patterns are always included by default
|
|
340
|
-
(see [TEST_FILE_PATTERNS in constants.ts][
|
|
344
|
+
(see [TEST_FILE_PATTERNS in constants.ts][14]):
|
|
341
345
|
|
|
342
346
|
- `**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}`
|
|
343
347
|
- `**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs}`
|
|
@@ -419,10 +423,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
|
|
|
419
423
|
|
|
420
424
|
Knip provides the following built-in reporters:
|
|
421
425
|
|
|
422
|
-
-
|
|
423
|
-
-
|
|
424
|
-
-
|
|
425
|
-
-
|
|
426
|
+
- `codeowners`
|
|
427
|
+
- `compact`
|
|
428
|
+
- `json`
|
|
429
|
+
- `symbol` (default)
|
|
426
430
|
|
|
427
431
|
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
428
432
|
|
|
@@ -449,7 +453,7 @@ type ReporterOptions = {
|
|
|
449
453
|
|
|
450
454
|
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
451
455
|
|
|
452
|
-
Find more details and ideas in [custom reporters][
|
|
456
|
+
Find more details and ideas in [custom reporters][15].
|
|
453
457
|
|
|
454
458
|
## Libraries and "unused" exports
|
|
455
459
|
|
|
@@ -503,11 +507,11 @@ instance by ignoring specific folders that are not related to the source code im
|
|
|
503
507
|
Dependencies that are only imported in unused files are also marked as unused. So a long list of unused files would be
|
|
504
508
|
good to remedy first.
|
|
505
509
|
|
|
506
|
-
When unused dependencies are related to dependencies having a Knip [plugin][
|
|
510
|
+
When unused dependencies are related to dependencies having a Knip [plugin][2], maybe the `config` and/or `entry` files
|
|
507
511
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
508
512
|
to match the custom location(s).
|
|
509
513
|
|
|
510
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
514
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][16].
|
|
511
515
|
|
|
512
516
|
#### Too many unused exports
|
|
513
517
|
|
|
@@ -515,7 +519,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
515
519
|
|
|
516
520
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
517
521
|
add the containing file to the `entry` array in the configuration.
|
|
518
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
522
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][17].
|
|
519
523
|
|
|
520
524
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
521
525
|
|
|
@@ -535,22 +539,22 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
535
539
|
|
|
536
540
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
537
541
|
|
|
538
|
-
| Feature
|
|
539
|
-
|
|
|
540
|
-
| Unused files
|
|
541
|
-
| Unused dependencies
|
|
542
|
-
| Unlisted dependencies
|
|
543
|
-
| [Plugins][
|
|
544
|
-
| Unused exports
|
|
545
|
-
| Unused class members
|
|
546
|
-
| Unused enum members
|
|
547
|
-
| Duplicate exports
|
|
548
|
-
| Search namespaces
|
|
549
|
-
| Custom reporters
|
|
550
|
-
| JavaScript support
|
|
551
|
-
| Configure entry files
|
|
552
|
-
| [Support workspaces/monorepos][
|
|
553
|
-
| ESLint plugin available
|
|
542
|
+
| Feature | **knip** | [depcheck][18] | [unimported][19] | [ts-unused-exports][20] | [ts-prune][21] |
|
|
543
|
+
| :-------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
544
|
+
| Unused files | ✅ | - | ✅ | - | - |
|
|
545
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
546
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - |
|
|
547
|
+
| [Plugins][2] | ✅ | ✅ | ❌ | - | - |
|
|
548
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ |
|
|
549
|
+
| Unused class members | ✅ | - | - | - | - |
|
|
550
|
+
| Unused enum members | ✅ | - | - | - | - |
|
|
551
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ |
|
|
552
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ |
|
|
553
|
+
| Custom reporters | ✅ | - | - | - | - |
|
|
554
|
+
| JavaScript support | ✅ | ✅ | ✅ | - | - |
|
|
555
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
556
|
+
| [Support workspaces/monorepos][1] | ✅ | ❌ | ❌ | - | - |
|
|
557
|
+
| ESLint plugin available | - | - | - | ✅ | - |
|
|
554
558
|
|
|
555
559
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
556
560
|
|
|
@@ -570,7 +574,7 @@ The following commands are similar:
|
|
|
570
574
|
unimported
|
|
571
575
|
knip --production --dependencies --include files
|
|
572
576
|
|
|
573
|
-
Also see [production mode][
|
|
577
|
+
Also see [production mode][22].
|
|
574
578
|
|
|
575
579
|
### ts-unused-exports
|
|
576
580
|
|
|
@@ -600,6 +604,12 @@ userland territory, much like code linters.
|
|
|
600
604
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
601
605
|
for the job. I'm motivated to make knip perfectly suited for the job of cutting projects to perfection! ✂️
|
|
602
606
|
|
|
607
|
+
## Contributors
|
|
608
|
+
|
|
609
|
+
Special thanks to the wonderful people who have contributed to this project:
|
|
610
|
+
|
|
611
|
+
[![Contributors][24]][23]
|
|
612
|
+
|
|
603
613
|
[1]: #workspaces--monorepos
|
|
604
614
|
[2]: #plugins
|
|
605
615
|
[3]: #reporters
|
|
@@ -612,50 +622,52 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
612
622
|
[10]: https://github.com/webpro/knip/issues
|
|
613
623
|
[11]: #faq
|
|
614
624
|
[12]: #ignore
|
|
615
|
-
[13]:
|
|
616
|
-
[14]:
|
|
617
|
-
[15]: ./
|
|
618
|
-
[16]:
|
|
619
|
-
[17]:
|
|
620
|
-
[18]:
|
|
621
|
-
[19]:
|
|
622
|
-
[20]:
|
|
623
|
-
[21]:
|
|
624
|
-
[22]:
|
|
625
|
-
[23]:
|
|
626
|
-
[24]:
|
|
627
|
-
[
|
|
628
|
-
[
|
|
629
|
-
[
|
|
630
|
-
[
|
|
631
|
-
[
|
|
632
|
-
[
|
|
633
|
-
[
|
|
634
|
-
[
|
|
635
|
-
[
|
|
636
|
-
[
|
|
637
|
-
[
|
|
638
|
-
[
|
|
639
|
-
[
|
|
640
|
-
[
|
|
641
|
-
[
|
|
642
|
-
[
|
|
643
|
-
[
|
|
644
|
-
[
|
|
645
|
-
[
|
|
646
|
-
[
|
|
647
|
-
[
|
|
648
|
-
[
|
|
649
|
-
[
|
|
650
|
-
[
|
|
651
|
-
[
|
|
652
|
-
[
|
|
653
|
-
[
|
|
654
|
-
[
|
|
655
|
-
[
|
|
656
|
-
[
|
|
657
|
-
[
|
|
658
|
-
[
|
|
659
|
-
[
|
|
660
|
-
[
|
|
661
|
-
[
|
|
625
|
+
[13]: #config
|
|
626
|
+
[14]: https://github.com/webpro/knip/blob/main/src/constants.ts
|
|
627
|
+
[15]: ./docs/custom-reporters.md
|
|
628
|
+
[16]: #create-a-new-plugin
|
|
629
|
+
[17]: #libraries-and-unused-exports
|
|
630
|
+
[18]: https://github.com/depcheck/depcheck
|
|
631
|
+
[19]: https://github.com/smeijer/unimported
|
|
632
|
+
[20]: https://github.com/pzavolinsky/ts-unused-exports
|
|
633
|
+
[21]: https://github.com/nadeesha/ts-prune
|
|
634
|
+
[22]: #production-mode
|
|
635
|
+
[23]: https://github.com/webpro/knip/graphs/contributors
|
|
636
|
+
[24]: https://contrib.rocks/image?repo=webpro/knip
|
|
637
|
+
[plugin-ava]: ./src/plugins/ava
|
|
638
|
+
[plugin-babel]: ./src/plugins/babel
|
|
639
|
+
[plugin-capacitor]: ./src/plugins/capacitor
|
|
640
|
+
[plugin-changesets]: ./src/plugins/changesets
|
|
641
|
+
[plugin-commitizen]: ./src/plugins/commitizen
|
|
642
|
+
[plugin-commitlint]: ./src/plugins/commitlint
|
|
643
|
+
[plugin-cspell]: ./src/plugins/cspell
|
|
644
|
+
[plugin-cypress]: ./src/plugins/cypress
|
|
645
|
+
[plugin-eslint]: ./src/plugins/eslint
|
|
646
|
+
[plugin-gatsby]: ./src/plugins/gatsby
|
|
647
|
+
[plugin-github-actions]: ./src/plugins/github-actions
|
|
648
|
+
[plugin-husky]: ./src/plugins/husky
|
|
649
|
+
[plugin-jest]: ./src/plugins/jest
|
|
650
|
+
[plugin-lefthook]: ./src/plugins/lefthook
|
|
651
|
+
[plugin-lint-staged]: ./src/plugins/lint-staged
|
|
652
|
+
[plugin-markdownlint]: ./src/plugins/markdownlint
|
|
653
|
+
[plugin-mocha]: ./src/plugins/mocha
|
|
654
|
+
[plugin-next]: ./src/plugins/next
|
|
655
|
+
[plugin-npm-package-json-lint]: ./src/plugins/npm-package-json-lint
|
|
656
|
+
[plugin-nx]: ./src/plugins/nx
|
|
657
|
+
[plugin-nyc]: ./src/plugins/nyc
|
|
658
|
+
[plugin-playwright]: ./src/plugins/playwright
|
|
659
|
+
[plugin-postcss]: ./src/plugins/postcss
|
|
660
|
+
[plugin-prettier]: ./src/plugins/prettier
|
|
661
|
+
[plugin-release-it]: ./src/plugins/release-it
|
|
662
|
+
[plugin-remark]: ./src/plugins/remark
|
|
663
|
+
[plugin-remix]: ./src/plugins/remix
|
|
664
|
+
[plugin-rollup]: ./src/plugins/rollup
|
|
665
|
+
[plugin-semantic-release]: ./src/plugins/semantic-release
|
|
666
|
+
[plugin-sentry]: ./src/plugins/sentry
|
|
667
|
+
[plugin-storybook]: ./src/plugins/storybook
|
|
668
|
+
[plugin-stryker]: ./src/plugins/stryker
|
|
669
|
+
[plugin-tailwind]: ./src/plugins/tailwind
|
|
670
|
+
[plugin-typedoc]: ./src/plugins/typedoc
|
|
671
|
+
[plugin-typescript]: ./src/plugins/typescript
|
|
672
|
+
[plugin-vitest]: ./src/plugins/vitest
|
|
673
|
+
[plugin-webpack]: ./src/plugins/webpack
|