knip 2.19.6 → 2.19.8

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 CHANGED
@@ -32,45 +32,46 @@ 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
- 📡 For updates, watch this repository or follow [@webprolific (Twitter)][8] or [@webpro (fosstodon.org)][9].
35
+ For updates or questions, come hang out in [The Knip Barn (Discord)][8], or follow [@webprolific (Twitter)][9] or
36
+ [@webpro (fosstodon.org)][10]. Please use GitHub to [report issues][11].
36
37
 
37
38
  ## Contents
38
39
 
39
- - [Getting Started][10]
40
- - [Installation][11]
41
- - [Default Configuration][12]
42
- - [Let's Go!][13]
43
- - [Configuration][14]
44
- - [Entry Files][15]
40
+ - [Getting Started][12]
41
+ - [Installation][13]
42
+ - [Default Configuration][14]
43
+ - [Let's Go!][15]
44
+ - [Configuration][16]
45
+ - [Entry Files][17]
45
46
  - [Workspaces][1]
46
47
  - [Plugins][2]
47
48
  - [Compilers][3]
48
- - [Ignore files, binaries, dependencies and workspaces][16]
49
- - [Public exports][17]
50
- - [Ignore exports used in file][18]
51
- - [Include exports in entry files][19]
52
- - [Paths][20]
53
- - [Production Mode][21]
54
- - [Strict][22]
55
- - [Plugins][23]
56
- - [Output][24]
57
- - [Screenshots][25]
58
- - [Reading the report][26]
59
- - [Rules & Filters][27]
49
+ - [Ignore files, binaries, dependencies and workspaces][18]
50
+ - [Public exports][19]
51
+ - [Ignore exports used in file][20]
52
+ - [Include exports in entry files][21]
53
+ - [Paths][22]
54
+ - [Production Mode][23]
55
+ - [Strict][24]
56
+ - [Plugins][25]
57
+ - [Output][26]
58
+ - [Screenshots][27]
59
+ - [Reading the report][28]
60
+ - [Rules & Filters][29]
60
61
  - [Reporters][4]
61
- - [Fixing Issues][28]
62
- - [Command Line Options][29]
63
- - [Potential boost with `--no-gitignore`][30]
64
- - [Comparison & Migration][31]
65
- - [depcheck][32]
66
- - [unimported][33]
67
- - [ts-unused-exports][34]
68
- - [ts-prune][35]
69
- - [Projects using Knip][36]
70
- - [Articles, etc.][37]
71
- - [Why "Knip"?][38]
72
- - [Really, another unused file/dependency/export finder?][39]
73
- - [Contributors][40]
62
+ - [Fixing Issues][30]
63
+ - [Command Line Options][31]
64
+ - [Potential boost with `--no-gitignore`][32]
65
+ - [Comparison & Migration][33]
66
+ - [depcheck][34]
67
+ - [unimported][35]
68
+ - [ts-unused-exports][36]
69
+ - [ts-prune][37]
70
+ - [Projects using Knip][38]
71
+ - [Articles, etc.][39]
72
+ - [Why "Knip"?][40]
73
+ - [Really, another unused file/dependency/export finder?][41]
74
+ - [Contributors][42]
74
75
 
75
76
  ## Getting Started
76
77
 
@@ -91,7 +92,7 @@ Knip has good defaults and you can run it without any configuration. The (simpli
91
92
  }
92
93
  ```
93
94
 
94
- There's more, jump to [Entry Files][15] for details.
95
+ There's more, jump to [Entry Files][17] for details.
95
96
 
96
97
  Places where Knip looks for configuration (ordered by priority):
97
98
 
@@ -133,7 +134,7 @@ Run the checks with `npx knip`. Or first add this script to `package.json`:
133
134
  Then use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine
134
135
  with `yarn` or `pnpm` as well.
135
136
 
136
- See [Command Line Options][29] for an overview of available CLI options.
137
+ See [Command Line Options][31] for an overview of available CLI options.
137
138
 
138
139
  ## Configuration
139
140
 
@@ -196,7 +197,7 @@ Here's an example `knip.json` configuration with some custom `entry` and `projec
196
197
  ```
197
198
 
198
199
  It might be useful to run Knip first with no or little configuration to see where it needs custom `entry` and/or
199
- `project` files. Each workspace has the same [default configuration][14].
200
+ `project` files. Each workspace has the same [default configuration][16].
200
201
 
201
202
  The root workspace is named `"."` under `workspaces` (like in the example).
202
203
 
@@ -319,7 +320,7 @@ has them at `e2e-tests/*.spec.ts`. Here's how to configure this:
319
320
  #### Multi-project repositories
320
321
 
321
322
  Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
322
- repository (such as the [Nx "intregrated repo" style][41]). Let's assume some of these projects are apps and have their
323
+ repository (such as the [Nx "intregrated repo" style][43]). Let's assume some of these projects are apps and have their
323
324
  own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
324
325
 
325
326
  ```json
@@ -336,7 +337,7 @@ In case a plugin causes issues, it can be disabled by using `false` as its value
336
337
 
337
338
  #### Create a new plugin
338
339
 
339
- Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][42]. This
340
+ Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][44]. This
340
341
  guide also contains more details if you want to learn more about plugins and why they are useful.
341
342
 
342
343
  ### Compilers
@@ -359,7 +360,7 @@ export default {
359
360
  };
360
361
  ```
361
362
 
362
- Read [Compilers][43] for more details and examples.
363
+ Read [Compilers][45] for more details and examples.
363
364
 
364
365
  ### Ignore files, binaries, dependencies and workspaces
365
366
 
@@ -521,7 +522,7 @@ The report contains the following types of issues:
521
522
 
522
523
  When an issue type has zero issues, it is not shown.
523
524
 
524
- Getting too many reported issues and false positives? Read more about [handling issues][44].
525
+ Getting too many reported issues and false positives? Read more about [handling issues][46].
525
526
 
526
527
  ### Rules & Filters
527
528
 
@@ -548,7 +549,7 @@ Example:
548
549
  }
549
550
  ```
550
551
 
551
- See [reading the report][26] for the list of issue types.
552
+ See [reading the report][28] for the list of issue types.
552
553
 
553
554
  The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
554
555
  apply filters or configurations only to a specific issue type.
@@ -569,7 +570,7 @@ Use `--exclude` to ignore reports you're not interested in:
569
570
 
570
571
  Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
571
572
 
572
- See [reading the report][26] for the list of issue types.
573
+ See [reading the report][28] for the list of issue types.
573
574
 
574
575
  #### When to use rules or filters
575
576
 
@@ -596,7 +597,7 @@ When the provided built-in reporters are not sufficient, a custom reporter can b
596
597
  Pass something like `--reporter ./my-reporter` from the command line. The results are passed to the function from its
597
598
  default export and can be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
598
599
 
599
- Find more details and ideas in [custom reporters][45].
600
+ Find more details and ideas in [custom reporters][47].
600
601
 
601
602
  ## Fixing Issues
602
603
 
@@ -614,7 +615,7 @@ Tip: back up files or use an VCS like Git before deleting files or making change
614
615
 
615
616
  Repeat the process to reveal new unused files and exports. It's so liberating to remove unused things!
616
617
 
617
- Getting too many reported issues and false positives? Read more about [handling issues][46] describing potential causes
618
+ Getting too many reported issues and false positives? Read more about [handling issues][48] describing potential causes
618
619
  for false positives, and how to handle them.
619
620
 
620
621
  ## Command Line Options
@@ -663,13 +664,13 @@ for false positives, and how to handle them.
663
664
 
664
665
  ## Potential boost with `--no-gitignore`
665
666
 
666
- To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][47].
667
+ To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][49].
667
668
 
668
669
  ## Comparison & Migration
669
670
 
670
671
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
671
672
 
672
- | Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
673
+ | Feature | **knip** | [depcheck][50] | [unimported][51] | [ts-unused-exports][52] | [ts-prune][53] |
673
674
  | :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
674
675
  | Unused files | ✅ | - | ✅ | - | - |
675
676
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -705,7 +706,7 @@ The following commands are similar:
705
706
  unimported
706
707
  knip --production --dependencies --include files
707
708
 
708
- Also see [production mode][21].
709
+ Also see [production mode][23].
709
710
 
710
711
  ### ts-unused-exports
711
712
 
@@ -727,28 +728,29 @@ The following commands are similar:
727
728
 
728
729
  Many thanks to some of the early adopters of Knip:
729
730
 
730
- - [Block Protocol][52]
731
- - [DeepmergeTS][53]
732
- - [eslint-plugin-functional][54]
733
- - [freeCodeCamp.org][55]
734
- - [is-immutable-type][56]
735
- - [IsaacScript][57]
736
- - [Nuxt][58]
737
- - [Owncast][59]
738
- - [release-it][60]
739
- - [Template TypeScript Node Package][61]
740
- - [Tipi][62]
731
+ - [Block Protocol][54]
732
+ - [DeepmergeTS][55]
733
+ - [eslint-plugin-functional][56]
734
+ - [freeCodeCamp.org][57]
735
+ - [is-immutable-type][58]
736
+ - [IsaacScript][59]
737
+ - [Nuxt][60]
738
+ - [Owncast][61]
739
+ - [release-it][62]
740
+ - [Template TypeScript Node Package][63]
741
+ - [Tipi][64]
741
742
 
742
743
  ## Articles, etc.
743
744
 
744
- - Ask your questions in the [Knip knowledge base][63] (powered by OpenAI and [7-docs][64], experimental!)
745
- - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][65]
746
- - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][66]
745
+ - Discord: hang out in [The Knip Barn][8]
746
+ - Ask your questions in the [Knip knowledge base][65] (powered by OpenAI and [7-docs][66], experimental!)
747
+ - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][67]
748
+ - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][68]
747
749
 
748
750
  ## Why "Knip"?
749
751
 
750
- Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
751
- for the job. I'm motivated to make Knip perfectly suited for the job of cutting projects to perfection! ✂️
752
+ Knip is Dutch for a "cut". A Dutch expression is "ergens ge**knip**t voor zijn", which means to be perfectly suited for
753
+ the job. I'm motivated to make Knip perfectly suited for the job of cutting projects to perfection! ✂️
752
754
 
753
755
  ## Really, another unused file/dependency/export finder?
754
756
 
@@ -761,7 +763,7 @@ each file, and traversing all of this, why not collect the various issues in one
761
763
 
762
764
  Special thanks to the wonderful people who have contributed to this project:
763
765
 
764
- [![Contributors][68]][67]
766
+ [![Contributors][70]][69]
765
767
 
766
768
  [1]: #workspaces
767
769
  [2]: #plugins
@@ -770,67 +772,69 @@ Special thanks to the wonderful people who have contributed to this project:
770
772
  [5]: #custom-reporters
771
773
  [6]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
772
774
  [7]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
773
- [8]: https://twitter.com/webprolific
774
- [9]: https://fosstodon.org/@webpro
775
- [10]: #getting-started
776
- [11]: #installation
777
- [12]: #default-configuration
778
- [13]: #lets-go
779
- [14]: #configuration
780
- [15]: #entry-files
781
- [16]: #ignore-files-binaries-dependencies-and-workspaces
782
- [17]: #public-exports
783
- [18]: #ignore-exports-used-in-file
784
- [19]: #include-exports-in-entry-files
785
- [20]: #paths
786
- [21]: #production-mode
787
- [22]: #strict
788
- [23]: #plugins-1
789
- [24]: #output
790
- [25]: #screenshots
791
- [26]: #reading-the-report
792
- [27]: #rules--filters
793
- [28]: #fixing-issues
794
- [29]: #command-line-options
795
- [30]: #potential-boost-with---no-gitignore
796
- [31]: #comparison--migration
797
- [32]: #depcheck
798
- [33]: #unimported
799
- [34]: #ts-unused-exports
800
- [35]: #ts-prune
801
- [36]: #projects-using-knip
802
- [37]: #articles-etc
803
- [38]: #why-knip
804
- [39]: #really-another-unused-filedependencyexport-finder
805
- [40]: #contributors
806
- [41]: https://nx.dev/concepts/integrated-vs-package-based
807
- [42]: ./docs/writing-a-plugin.md
808
- [43]: ./docs/compilers.md
809
- [44]: #handling-issues
810
- [45]: ./docs/custom-reporters.md
811
- [46]: ./docs/handling-issues.md
812
- [47]: ./docs/perf-boost-with-no-gitignore.md
813
- [48]: https://github.com/depcheck/depcheck
814
- [49]: https://github.com/smeijer/unimported
815
- [50]: https://github.com/pzavolinsky/ts-unused-exports
816
- [51]: https://github.com/nadeesha/ts-prune
817
- [52]: https://github.com/blockprotocol/blockprotocol
818
- [53]: https://github.com/RebeccaStevens/deepmerge-ts
819
- [54]: https://github.com/eslint-functional/eslint-plugin-functional
820
- [55]: https://github.com/freeCodeCamp/freeCodeCamp
821
- [56]: https://github.com/RebeccaStevens/is-immutable-type
822
- [57]: https://github.com/IsaacScript/isaacscript
823
- [58]: https://github.com/nuxt/nuxt
824
- [59]: https://github.com/owncast/owncast
825
- [60]: https://github.com/release-it/release-it
826
- [61]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
827
- [62]: https://github.com/meienberger/runtipi
828
- [63]: https://knip.deno.dev
829
- [64]: https://github.com/7-docs/7-docs
830
- [65]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
831
- [66]: https://effectivetypescript.com/2023/07/29/knip/
832
- [67]: https://github.com/webpro/knip/graphs/contributors
833
- [68]: https://contrib.rocks/image?repo=webpro/knip
775
+ [8]: https://discord.gg/ya5yktTq
776
+ [9]: https://twitter.com/webprolific
777
+ [10]: https://fosstodon.org/@webpro
778
+ [11]: https://github.com/webpro/knip/issues
779
+ [12]: #getting-started
780
+ [13]: #installation
781
+ [14]: #default-configuration
782
+ [15]: #lets-go
783
+ [16]: #configuration
784
+ [17]: #entry-files
785
+ [18]: #ignore-files-binaries-dependencies-and-workspaces
786
+ [19]: #public-exports
787
+ [20]: #ignore-exports-used-in-file
788
+ [21]: #include-exports-in-entry-files
789
+ [22]: #paths
790
+ [23]: #production-mode
791
+ [24]: #strict
792
+ [25]: #plugins-1
793
+ [26]: #output
794
+ [27]: #screenshots
795
+ [28]: #reading-the-report
796
+ [29]: #rules--filters
797
+ [30]: #fixing-issues
798
+ [31]: #command-line-options
799
+ [32]: #potential-boost-with---no-gitignore
800
+ [33]: #comparison--migration
801
+ [34]: #depcheck
802
+ [35]: #unimported
803
+ [36]: #ts-unused-exports
804
+ [37]: #ts-prune
805
+ [38]: #projects-using-knip
806
+ [39]: #articles-etc
807
+ [40]: #why-knip
808
+ [41]: #really-another-unused-filedependencyexport-finder
809
+ [42]: #contributors
810
+ [43]: https://nx.dev/concepts/integrated-vs-package-based
811
+ [44]: ./docs/writing-a-plugin.md
812
+ [45]: ./docs/compilers.md
813
+ [46]: #handling-issues
814
+ [47]: ./docs/custom-reporters.md
815
+ [48]: ./docs/handling-issues.md
816
+ [49]: ./docs/perf-boost-with-no-gitignore.md
817
+ [50]: https://github.com/depcheck/depcheck
818
+ [51]: https://github.com/smeijer/unimported
819
+ [52]: https://github.com/pzavolinsky/ts-unused-exports
820
+ [53]: https://github.com/nadeesha/ts-prune
821
+ [54]: https://github.com/blockprotocol/blockprotocol
822
+ [55]: https://github.com/RebeccaStevens/deepmerge-ts
823
+ [56]: https://github.com/eslint-functional/eslint-plugin-functional
824
+ [57]: https://github.com/freeCodeCamp/freeCodeCamp
825
+ [58]: https://github.com/RebeccaStevens/is-immutable-type
826
+ [59]: https://github.com/IsaacScript/isaacscript
827
+ [60]: https://github.com/nuxt/nuxt
828
+ [61]: https://github.com/owncast/owncast
829
+ [62]: https://github.com/release-it/release-it
830
+ [63]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
831
+ [64]: https://github.com/meienberger/runtipi
832
+ [65]: https://knip.deno.dev
833
+ [66]: https://github.com/7-docs/7-docs
834
+ [67]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
835
+ [68]: https://effectivetypescript.com/2023/07/29/knip/
836
+ [69]: https://github.com/webpro/knip/graphs/contributors
837
+ [70]: https://contrib.rocks/image?repo=webpro/knip
834
838
  [plugin-ava]: ./src/plugins/ava
835
839
  [plugin-babel]: ./src/plugins/babel
836
840
  [plugin-capacitor]: ./src/plugins/capacitor
@@ -58,6 +58,7 @@ export declare class ProjectPrincipal {
58
58
  };
59
59
  findUnusedMembers(filePath: string, members: ExportItemMember[]): string[];
60
60
  private findReferences;
61
- isPublicExport(exportedItem: ExportItem): ts.JSDocPublicTag | undefined;
61
+ isPublicExport(exportedItem: ExportItem): boolean;
62
+ getJSDocTags(exportedItem: ExportItem): string[];
62
63
  }
63
64
  export {};
@@ -195,6 +195,10 @@ export class ProjectPrincipal {
195
195
  return this.backend.lsFindReferences(filePath, node.getStart()) ?? [];
196
196
  }
197
197
  isPublicExport(exportedItem) {
198
- return ts.getJSDocPublicTag(exportedItem.node);
198
+ const tags = this.getJSDocTags(exportedItem);
199
+ return tags.includes('@public');
200
+ }
201
+ getJSDocTags(exportedItem) {
202
+ return ts.getJSDocTags(exportedItem.node).map(node => node.getText().match(/@\S+/)[0]);
199
203
  }
200
204
  }
@@ -2,38 +2,54 @@ import parseArgs from 'minimist';
2
2
  import { toBinary } from '../util.js';
3
3
  const commands = [
4
4
  'add',
5
+ 'audit',
6
+ 'bin',
7
+ 'config',
5
8
  'dedupe',
9
+ 'deploy',
6
10
  'dlx',
7
- 'run',
11
+ 'doctor',
12
+ 'env',
13
+ 'fetch',
8
14
  'i',
9
- 'install',
10
- 'up',
11
- 'update',
12
- 'upgrade',
13
- 'remove',
14
- 'rm',
15
- 'uninstall',
16
- 'un',
17
- 'link',
18
- 'ln',
19
- 'unlink',
20
15
  'import',
21
- 'rebuild',
22
- 'rb',
23
- 'prune',
24
- 'fetch',
16
+ 'init',
25
17
  'install-test',
18
+ 'install',
26
19
  'it',
27
- 'patch',
28
- 'patch-commit',
29
- 'audit',
20
+ 'licenses',
21
+ 'link',
30
22
  'list',
23
+ 'ln',
31
24
  'ls',
32
25
  'outdated',
33
- 'why',
34
- 'test',
26
+ 'outdated',
27
+ 'pack',
28
+ 'patch-commit',
29
+ 'patch-remove',
30
+ 'patch',
31
+ 'prune',
32
+ 'publish',
33
+ 'rb',
34
+ 'rebuild',
35
+ 'remove',
36
+ 'rm',
37
+ 'root',
38
+ 'run',
39
+ 'server',
40
+ 'setup',
41
+ 'start',
42
+ 'store',
35
43
  't',
44
+ 'test',
36
45
  'tst',
46
+ 'un',
47
+ 'uninstall',
48
+ 'unlink',
49
+ 'up',
50
+ 'update',
51
+ 'upgrade',
52
+ 'why',
37
53
  ];
38
54
  export const resolve = (_binary, args, { manifest }) => {
39
55
  const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
@@ -14,8 +14,8 @@ const commands = [
14
14
  'install',
15
15
  'link',
16
16
  'pack',
17
- 'patch',
18
17
  'patch-commit',
18
+ 'patch',
19
19
  'plugin',
20
20
  'rebuild',
21
21
  'remove',
@@ -25,8 +25,8 @@ const commands = [
25
25
  'unlink',
26
26
  'unplug',
27
27
  'up',
28
- 'upgrade',
29
28
  'upgrade-interactive',
29
+ 'upgrade',
30
30
  'version',
31
31
  'why',
32
32
  'workspace',
package/dist/index.js CHANGED
@@ -267,7 +267,8 @@ export const main = async (unresolvedConfiguration) => {
267
267
  continue;
268
268
  const importedModule = importedSymbols.get(filePath);
269
269
  for (const [symbol, exportedItem] of exportItems.entries()) {
270
- if (principal.isPublicExport(exportedItem))
270
+ const jsDocTags = principal.getJSDocTags(exportedItem);
271
+ if (jsDocTags.includes('@public') || jsDocTags.includes('@beta'))
271
272
  continue;
272
273
  if (importedModule?.symbols.has(symbol)) {
273
274
  if (importedModule.isReExport && isExportedInEntryFile(importedModule))
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.19.6";
1
+ export declare const version = "2.19.8";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.6';
1
+ export const version = '2.19.8';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.19.6",
3
+ "version": "2.19.8",
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",
@@ -56,7 +56,7 @@
56
56
  "strip-json-comments": "^5.0.0",
57
57
  "summary": "^2.1.0",
58
58
  "tree-sitter": "0.20.5",
59
- "tree-sitter-bash": "0.20.0",
59
+ "tree-sitter-bash": "0.19.0",
60
60
  "typescript": "^5.0.2",
61
61
  "zod": "^3.22.2",
62
62
  "zod-validation-error": "^1.5.0"