knip 2.20.1 → 2.20.2

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
@@ -53,25 +53,26 @@ For updates or questions, come hang out in [The Knip Barn (Discord)][8], or foll
53
53
  - [Paths][22]
54
54
  - [Production Mode][23]
55
55
  - [Strict][24]
56
- - [Plugins][25]
57
- - [Output][26]
58
- - [Screenshots][27]
59
- - [Reading the report][28]
60
- - [Rules & Filters][29]
56
+ - [Ignore `@internal` exports][25]
57
+ - [Plugins][26]
58
+ - [Output][27]
59
+ - [Screenshots][28]
60
+ - [Reading the report][29]
61
+ - [Rules & Filters][30]
61
62
  - [Reporters][4]
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]
63
+ - [Fixing Issues][31]
64
+ - [Command Line Options][32]
65
+ - [Potential boost with `--no-gitignore`][33]
66
+ - [Comparison & Migration][34]
67
+ - [depcheck][35]
68
+ - [unimported][36]
69
+ - [ts-unused-exports][37]
70
+ - [ts-prune][38]
71
+ - [Projects using Knip][39]
72
+ - [Articles, etc.][40]
73
+ - [Why "Knip"?][41]
74
+ - [Really, another unused file/dependency/export finder?][42]
75
+ - [Contributors][43]
75
76
 
76
77
  ## Getting Started
77
78
 
@@ -134,7 +135,7 @@ Run the checks with `npx knip`. Or first add this script to `package.json`:
134
135
  Then use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine
135
136
  with `yarn` or `pnpm` as well.
136
137
 
137
- See [Command Line Options][31] for an overview of available CLI options.
138
+ See [Command Line Options][32] for an overview of available CLI options.
138
139
 
139
140
  ## Configuration
140
141
 
@@ -320,7 +321,7 @@ has them at `e2e-tests/*.spec.ts`. Here's how to configure this:
320
321
  #### Multi-project repositories
321
322
 
322
323
  Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
323
- repository (such as the [Nx "intregrated repo" style][43]). Let's assume some of these projects are apps and have their
324
+ repository (such as the [Nx "intregrated repo" style][44]). Let's assume some of these projects are apps and have their
324
325
  own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
325
326
 
326
327
  ```json
@@ -337,7 +338,7 @@ In case a plugin causes issues, it can be disabled by using `false` as its value
337
338
 
338
339
  #### Create a new plugin
339
340
 
340
- Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][44]. This
341
+ Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][45]. This
341
342
  guide also contains more details if you want to learn more about plugins and why they are useful.
342
343
 
343
344
  ### Compilers
@@ -360,7 +361,7 @@ export default {
360
361
  };
361
362
  ```
362
363
 
363
- Read [Compilers][45] for more details and examples.
364
+ Read [Compilers][46] for more details and examples.
364
365
 
365
366
  ### Ignore files, binaries, dependencies and workspaces
366
367
 
@@ -527,7 +528,7 @@ The report contains the following types of issues:
527
528
 
528
529
  When an issue type has zero issues, it is not shown.
529
530
 
530
- Getting too many reported issues and false positives? Read more about [handling issues][46].
531
+ Getting too many reported issues and false positives? Read more about [handling issues][47].
531
532
 
532
533
  ### Rules & Filters
533
534
 
@@ -554,7 +555,7 @@ Example:
554
555
  }
555
556
  ```
556
557
 
557
- See [reading the report][28] for the list of issue types.
558
+ See [reading the report][29] for the list of issue types.
558
559
 
559
560
  The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
560
561
  apply filters or configurations only to a specific issue type.
@@ -575,7 +576,7 @@ Use `--exclude` to ignore reports you're not interested in:
575
576
 
576
577
  Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
577
578
 
578
- See [reading the report][28] for the list of issue types.
579
+ See [reading the report][29] for the list of issue types.
579
580
 
580
581
  #### When to use rules or filters
581
582
 
@@ -602,7 +603,7 @@ When the provided built-in reporters are not sufficient, a custom reporter can b
602
603
  Pass something like `--reporter ./my-reporter` from the command line. The results are passed to the function from its
603
604
  default export and can be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
604
605
 
605
- Find more details and ideas in [custom reporters][47].
606
+ Find more details and ideas in [custom reporters][48].
606
607
 
607
608
  ## Fixing Issues
608
609
 
@@ -620,7 +621,7 @@ Tip: back up files or use an VCS like Git before deleting files or making change
620
621
 
621
622
  Repeat the process to reveal new unused files and exports. It's so liberating to remove unused things!
622
623
 
623
- Getting too many reported issues and false positives? Read more about [handling issues][48] describing potential causes
624
+ Getting too many reported issues and false positives? Read more about [handling issues][49] describing potential causes
624
625
  for false positives, and how to handle them.
625
626
 
626
627
  ## Command Line Options
@@ -670,13 +671,13 @@ for false positives, and how to handle them.
670
671
 
671
672
  ## Potential boost with `--no-gitignore`
672
673
 
673
- To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][49].
674
+ To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][50].
674
675
 
675
676
  ## Comparison & Migration
676
677
 
677
678
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
678
679
 
679
- | Feature | **knip** | [depcheck][50] | [unimported][51] | [ts-unused-exports][52] | [ts-prune][53] |
680
+ | Feature | **knip** | [depcheck][51] | [unimported][52] | [ts-unused-exports][53] | [ts-prune][54] |
680
681
  | :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
681
682
  | Unused files | ✅ | - | ✅ | - | - |
682
683
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -734,25 +735,25 @@ The following commands are similar:
734
735
 
735
736
  Many thanks to some of the early adopters of Knip:
736
737
 
737
- - [Block Protocol][54]
738
- - [DeepmergeTS][55]
739
- - [eslint-plugin-functional][56]
740
- - [freeCodeCamp.org][57]
741
- - [is-immutable-type][58]
742
- - [IsaacScript][59]
743
- - [Nuxt][60]
744
- - [Owncast][61]
745
- - [release-it][62]
746
- - [Template TypeScript Node Package][63]
747
- - [Tipi][64]
738
+ - [Block Protocol][55]
739
+ - [DeepmergeTS][56]
740
+ - [eslint-plugin-functional][57]
741
+ - [freeCodeCamp.org][58]
742
+ - [is-immutable-type][59]
743
+ - [IsaacScript][60]
744
+ - [Nuxt][61]
745
+ - [Owncast][62]
746
+ - [release-it][63]
747
+ - [Template TypeScript Node Package][64]
748
+ - [Tipi][65]
748
749
 
749
750
  ## Articles, etc.
750
751
 
751
752
  - Discord: hang out in [The Knip Barn][8]
752
- - Ask your questions in the [Knip knowledge base][65] (powered by OpenAI and [7-docs][66], experimental!)
753
- - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][67]
754
- - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][68]
755
- - Josh Goldberg: [Speeding Up Centered Part 4: Unused Code Bloat][69]
753
+ - Ask your questions in the [Knip knowledge base][66] (powered by OpenAI and [7-docs][67], experimental!)
754
+ - Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][68]
755
+ - Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][69]
756
+ - Josh Goldberg: [Speeding Up Centered Part 4: Unused Code Bloat][70]
756
757
 
757
758
  ## Why "Knip"?
758
759
 
@@ -770,7 +771,7 @@ each file, and traversing all of this, why not collect the various issues in one
770
771
 
771
772
  Special thanks to the wonderful people who have contributed to this project:
772
773
 
773
- [![Contributors][71]][70]
774
+ [![Contributors][72]][71]
774
775
 
775
776
  [1]: #workspaces
776
777
  [2]: #plugins
@@ -796,53 +797,54 @@ Special thanks to the wonderful people who have contributed to this project:
796
797
  [22]: #paths
797
798
  [23]: #production-mode
798
799
  [24]: #strict
799
- [25]: #plugins-1
800
- [26]: #output
801
- [27]: #screenshots
802
- [28]: #reading-the-report
803
- [29]: #rules--filters
804
- [30]: #fixing-issues
805
- [31]: #command-line-options
806
- [32]: #potential-boost-with---no-gitignore
807
- [33]: #comparison--migration
808
- [34]: #depcheck
809
- [35]: #unimported
810
- [36]: #ts-unused-exports
811
- [37]: #ts-prune
812
- [38]: #projects-using-knip
813
- [39]: #articles-etc
814
- [40]: #why-knip
815
- [41]: #really-another-unused-filedependencyexport-finder
816
- [42]: #contributors
817
- [43]: https://nx.dev/concepts/integrated-vs-package-based
818
- [44]: ./docs/writing-a-plugin.md
819
- [45]: ./docs/compilers.md
820
- [46]: #handling-issues
821
- [47]: ./docs/custom-reporters.md
822
- [48]: ./docs/handling-issues.md
823
- [49]: ./docs/perf-boost-with-no-gitignore.md
824
- [50]: https://github.com/depcheck/depcheck
825
- [51]: https://github.com/smeijer/unimported
826
- [52]: https://github.com/pzavolinsky/ts-unused-exports
827
- [53]: https://github.com/nadeesha/ts-prune
828
- [54]: https://github.com/blockprotocol/blockprotocol
829
- [55]: https://github.com/RebeccaStevens/deepmerge-ts
830
- [56]: https://github.com/eslint-functional/eslint-plugin-functional
831
- [57]: https://github.com/freeCodeCamp/freeCodeCamp
832
- [58]: https://github.com/RebeccaStevens/is-immutable-type
833
- [59]: https://github.com/IsaacScript/isaacscript
834
- [60]: https://github.com/nuxt/nuxt
835
- [61]: https://github.com/owncast/owncast
836
- [62]: https://github.com/release-it/release-it
837
- [63]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
838
- [64]: https://github.com/meienberger/runtipi
839
- [65]: https://knip.deno.dev
840
- [66]: https://github.com/7-docs/7-docs
841
- [67]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
842
- [68]: https://effectivetypescript.com/2023/07/29/knip/
843
- [69]: https://www.joshuakgoldberg.com/blog/speeding-up-centered-part-4-unused-code-bloat/
844
- [70]: https://github.com/webpro/knip/graphs/contributors
845
- [71]: https://contrib.rocks/image?repo=webpro/knip
800
+ [25]: #ignore-internal-exports
801
+ [26]: #plugins-1
802
+ [27]: #output
803
+ [28]: #screenshots
804
+ [29]: #reading-the-report
805
+ [30]: #rules--filters
806
+ [31]: #fixing-issues
807
+ [32]: #command-line-options
808
+ [33]: #potential-boost-with---no-gitignore
809
+ [34]: #comparison--migration
810
+ [35]: #depcheck
811
+ [36]: #unimported
812
+ [37]: #ts-unused-exports
813
+ [38]: #ts-prune
814
+ [39]: #projects-using-knip
815
+ [40]: #articles-etc
816
+ [41]: #why-knip
817
+ [42]: #really-another-unused-filedependencyexport-finder
818
+ [43]: #contributors
819
+ [44]: https://nx.dev/concepts/integrated-vs-package-based
820
+ [45]: ./docs/writing-a-plugin.md
821
+ [46]: ./docs/compilers.md
822
+ [47]: #handling-issues
823
+ [48]: ./docs/custom-reporters.md
824
+ [49]: ./docs/handling-issues.md
825
+ [50]: ./docs/perf-boost-with-no-gitignore.md
826
+ [51]: https://github.com/depcheck/depcheck
827
+ [52]: https://github.com/smeijer/unimported
828
+ [53]: https://github.com/pzavolinsky/ts-unused-exports
829
+ [54]: https://github.com/nadeesha/ts-prune
830
+ [55]: https://github.com/blockprotocol/blockprotocol
831
+ [56]: https://github.com/RebeccaStevens/deepmerge-ts
832
+ [57]: https://github.com/eslint-functional/eslint-plugin-functional
833
+ [58]: https://github.com/freeCodeCamp/freeCodeCamp
834
+ [59]: https://github.com/RebeccaStevens/is-immutable-type
835
+ [60]: https://github.com/IsaacScript/isaacscript
836
+ [61]: https://github.com/nuxt/nuxt
837
+ [62]: https://github.com/owncast/owncast
838
+ [63]: https://github.com/release-it/release-it
839
+ [64]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
840
+ [65]: https://github.com/meienberger/runtipi
841
+ [66]: https://knip.deno.dev
842
+ [67]: https://github.com/7-docs/7-docs
843
+ [68]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
844
+ [69]: https://effectivetypescript.com/2023/07/29/knip/
845
+ [70]: https://www.joshuakgoldberg.com/blog/speeding-up-centered-part-4-unused-code-bloat/
846
+ [71]: https://github.com/webpro/knip/graphs/contributors
847
+ [72]: https://contrib.rocks/image?repo=webpro/knip
846
848
  [plugin-ava]: ./src/plugins/ava
847
849
  [plugin-babel]: ./src/plugins/babel
848
850
  [plugin-capacitor]: ./src/plugins/capacitor
@@ -49,7 +49,8 @@ export class WorkspaceWorker {
49
49
  if (this.config[pluginName] === false)
50
50
  continue;
51
51
  const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
52
- if (isEnabledInAncestor || (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies }))) {
52
+ if (isEnabledInAncestor ||
53
+ (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies, config: this.config }))) {
53
54
  this.enabled[pluginName] = true;
54
55
  }
55
56
  }
@@ -3,7 +3,8 @@ import { hasDependency } from '../../util/plugin.js';
3
3
  import { getDependenciesDeep } from './helpers.js';
4
4
  export const NAME = 'ESLint';
5
5
  export const ENABLERS = ['eslint'];
6
- export const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) ||
6
+ export const isEnabled = ({ dependencies, manifest, config }) => hasDependency(dependencies, ENABLERS) ||
7
+ 'eslint' in config ||
7
8
  Boolean(manifest.name && /(^eslint-config|\/eslint-config)/.test(manifest.name));
8
9
  export const CONFIG_FILE_PATTERNS = ['.eslintrc', '.eslintrc.{js,json,cjs}', '.eslintrc.{yml,yaml}', 'package.json'];
9
10
  export const ENTRY_FILE_PATTERNS = ['eslint.config.js'];
@@ -2,7 +2,7 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'Prettier';
4
4
  export const ENABLERS = ['prettier'];
5
- export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
+ export const isEnabled = ({ dependencies, config }) => hasDependency(dependencies, ENABLERS) || 'prettier' in config;
6
6
  export const CONFIG_FILE_PATTERNS = [
7
7
  '.prettierrc',
8
8
  '.prettierrc.{json,js,cjs,yml,yaml}',
@@ -1,11 +1,12 @@
1
1
  /// <reference types="npmcli__package-json" />
2
- import type { PluginConfiguration } from './config.js';
2
+ import type { PluginConfiguration, WorkspaceConfiguration } from './config.js';
3
3
  import type { PackageJson } from '@npmcli/package-json';
4
4
  export type PackageJsonWithPlugins = PackageJson & Record<string, unknown>;
5
5
  type IsPluginEnabledCallbackOptions = {
6
6
  cwd: string;
7
7
  manifest: PackageJson;
8
8
  dependencies: Set<string>;
9
+ config: WorkspaceConfiguration;
9
10
  };
10
11
  export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions) => boolean | Promise<boolean>;
11
12
  type GenericPluginCallbackOptions = {
@@ -112,10 +112,8 @@ export const getImportsAndExports = (sourceFile, options) => {
112
112
  for (const visitor of visitors.import) {
113
113
  if (visitor) {
114
114
  const results = visitor(node, options);
115
- if (results) {
115
+ if (results)
116
116
  [results].flat().forEach(addImport);
117
- return;
118
- }
119
117
  }
120
118
  }
121
119
  for (const visitor of visitors.export) {
@@ -128,10 +126,8 @@ export const getImportsAndExports = (sourceFile, options) => {
128
126
  for (const visitor of visitors.script) {
129
127
  if (visitor) {
130
128
  const results = visitor(node, options);
131
- if (results) {
129
+ if (results)
132
130
  [results].flat().forEach(script => scripts.add(script));
133
- return;
134
- }
135
131
  }
136
132
  }
137
133
  if (isAccessExpression(node)) {
@@ -4,4 +4,4 @@ import exportDeclaration from './exportDeclaration.js';
4
4
  import exportKeyword from './exportKeyword.js';
5
5
  import moduleExportsAccessExpression from './moduleExportsAccessExpression.js';
6
6
  const visitors = [exportAssignment, exportDeclaration, exportKeyword, moduleExportsAccessExpression];
7
- export default (sourceFile) => visitors.map(v => v(sourceFile)).filter(v => v);
7
+ export default (sourceFile) => visitors.map(v => v(sourceFile));
@@ -15,4 +15,4 @@ const visitors = [
15
15
  requireCall,
16
16
  requireResolveCall,
17
17
  ];
18
- export default (sourceFile) => visitors.map(v => v(sourceFile)).filter(v => v);
18
+ export default (sourceFile) => visitors.map(v => v(sourceFile));
@@ -2,4 +2,4 @@ import ts from 'typescript';
2
2
  import execa from './execa.js';
3
3
  import zx from './zx.js';
4
4
  const visitors = [execa, zx];
5
- export default (sourceFile) => visitors.map(v => v(sourceFile)).filter(v => v);
5
+ export default (sourceFile) => visitors.map(v => v(sourceFile));
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.20.1";
1
+ export declare const version = "2.20.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.20.1';
1
+ export const version = '2.20.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.20.1",
3
+ "version": "2.20.2",
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",