knip 1.4.0 → 1.5.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 CHANGED
@@ -234,26 +234,27 @@ Knip contains a growing list of plugins:
234
234
  - [ESLint][15]
235
235
  - [Gatsby][16]
236
236
  - [GitHub Actions][17]
237
- - [Jest][18]
238
- - [lint-staged][19]
239
- - [markdownlint][20]
240
- - [Mocha][21]
241
- - [Next.js][22]
242
- - [npm-package-json-lint][23]
243
- - [Nx][24]
244
- - [nyc][25]
245
- - [Playwright][26]
246
- - [PostCSS][27]
247
- - [Prettier][28]
248
- - [Release It][29]
249
- - [Remark][30]
250
- - [Remix][31]
251
- - [Rollup][32]
252
- - [Sentry][33]
253
- - [Storybook][34]
254
- - [Stryker][35]
255
- - [TypeScript][36]
256
- - [Webpack][37]
237
+ - [husky][18]
238
+ - [Jest][19]
239
+ - [lint-staged][20]
240
+ - [markdownlint][21]
241
+ - [Mocha][22]
242
+ - [Next.js][23]
243
+ - [npm-package-json-lint][24]
244
+ - [Nx][25]
245
+ - [nyc][26]
246
+ - [Playwright][27]
247
+ - [PostCSS][28]
248
+ - [Prettier][29]
249
+ - [Release It][30]
250
+ - [Remark][31]
251
+ - [Remix][32]
252
+ - [Rollup][33]
253
+ - [Sentry][34]
254
+ - [Storybook][35]
255
+ - [Stryker][36]
256
+ - [TypeScript][37]
257
+ - [Webpack][38]
257
258
 
258
259
  Plugins are automatically activated, no need to enable anything. Each plugin is automatically enabled based on simple
259
260
  heuristics. Most of them check whether one or one of a few (dev) dependencies are listed in `package.json`. Once
@@ -261,7 +262,7 @@ enabled, they add a set of configuration and/or entry files for Knip to analyze.
261
262
 
262
263
  Most plugins use one or both of the following file types:
263
264
 
264
- - `config` - custom dependency resolvers are applied to the [config files][38]
265
+ - `config` - custom dependency resolvers are applied to the [config files][39]
265
266
  - `entry` - files to include with the analysis of the rest of the source code
266
267
 
267
268
  See each plugin's documentation for its default values.
@@ -341,10 +342,10 @@ locations. The more plugins Knip will have, the more projects can be analyzed ou
341
342
 
342
343
  Knip provides the following built-in reporters:
343
344
 
344
- - [`codeowners`][39]
345
- - [`compact`][40]
346
- - [`json`][41]
347
- - [`symbol`][42] (default)
345
+ - [`codeowners`][40]
346
+ - [`compact`][41]
347
+ - [`json`][42]
348
+ - [`symbol`][43] (default)
348
349
 
349
350
  The `compact` reporter shows the sorted files first, and then a list of symbols:
350
351
 
@@ -371,7 +372,7 @@ type ReporterOptions = {
371
372
 
372
373
  The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
373
374
 
374
- Find more details and ideas in [custom reporters][43].
375
+ Find more details and ideas in [custom reporters][44].
375
376
 
376
377
  ## Libraries and "unused" exports
377
378
 
@@ -428,14 +429,14 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
428
429
  for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
429
430
  to match the custom location(s).
430
431
 
431
- When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][44].
432
+ When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][45].
432
433
 
433
434
  #### Too many unused exports
434
435
 
435
436
  When the project is a library and the exports are meant to be used by consumers of the library, there are two options:
436
437
 
437
438
  1. By default, unused exports of `entry` files are not reported, so you can add the containing file to it.
438
- 2. The exported values or types can be marked [using the JSDoc `@public` tag][45].
439
+ 2. The exported values or types can be marked [using the JSDoc `@public` tag][46].
439
440
 
440
441
  ### How to start using Knip in CI while having too many issues to sort out?
441
442
 
@@ -452,7 +453,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
452
453
 
453
454
  This table is an ongoing comparison. Based on their docs (please report any mistakes):
454
455
 
455
- | Feature | **knip** | [depcheck][46] | [unimported][47] | [ts-unused-exports][48] | [ts-prune][49] |
456
+ | Feature | **knip** | [depcheck][47] | [unimported][48] | [ts-unused-exports][49] | [ts-prune][50] |
456
457
  | :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
457
458
  | Unused files | ✅ | - | ✅ | - | - |
458
459
  | Unused dependencies | ✅ | ✅ | ✅ | - | - |
@@ -466,7 +467,7 @@ This table is an ongoing comparison. Based on their docs (please report any mist
466
467
  | Custom reporters | ✅ | - | - | - | - |
467
468
  | JavaScript support | ✅ | ✅ | ✅ | - | - |
468
469
  | Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
469
- | [Support workspaces/monorepos][50] | ✅ | ❌ | ❌ | - | - |
470
+ | [Support workspaces/monorepos][51] | ✅ | ❌ | ❌ | - | - |
470
471
  | ESLint plugin available | - | - | - | ✅ | - |
471
472
 
472
473
  ✅ = Supported, ❌ = Not supported, - = Out of scope
@@ -487,7 +488,7 @@ The following commands are similar:
487
488
  unimported
488
489
  knip --production --dependencies --include files
489
490
 
490
- Also see [production mode][51].
491
+ Also see [production mode][52].
491
492
 
492
493
  ### ts-unused-exports
493
494
 
@@ -534,37 +535,38 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
534
535
  [15]: ./src/plugins/eslint
535
536
  [16]: ./src/plugins/gatsby
536
537
  [17]: ./src/plugins/github-actions
537
- [18]: ./src/plugins/jest
538
- [19]: ./src/plugins/lint-staged
539
- [20]: ./src/plugins/markdownlint
540
- [21]: ./src/plugins/mocha
541
- [22]: ./src/plugins/next
542
- [23]: ./src/plugins/npm-package-json-lint
543
- [24]: ./src/plugins/nx
544
- [25]: ./src/plugins/nyc
545
- [26]: ./src/plugins/playwright
546
- [27]: ./src/plugins/postcss
547
- [28]: ./src/plugins/prettier
548
- [29]: ./src/plugins/release-it
549
- [30]: ./src/plugins/remark
550
- [31]: ./src/plugins/remix
551
- [32]: ./src/plugins/rollup
552
- [33]: ./src/plugins/sentry
553
- [34]: ./src/plugins/storybook
554
- [35]: ./src/plugins/stryker
555
- [36]: ./src/plugins/typescript
556
- [37]: ./src/plugins/webpack
557
- [38]: #config
558
- [39]: #code-owners
559
- [40]: #compact
560
- [41]: #json
561
- [42]: #symbol-default
562
- [43]: ./docs/custom-reporters.md
563
- [44]: #create-a-new-plugin
564
- [45]: #libraries-and-unused-exports
565
- [46]: https://github.com/depcheck/depcheck
566
- [47]: https://github.com/smeijer/unimported
567
- [48]: https://github.com/pzavolinsky/ts-unused-exports
568
- [49]: https://github.com/nadeesha/ts-prune
569
- [50]: #workspaces--monorepos
570
- [51]: #production-mode
538
+ [18]: ./src/plugins/husky
539
+ [19]: ./src/plugins/jest
540
+ [20]: ./src/plugins/lint-staged
541
+ [21]: ./src/plugins/markdownlint
542
+ [22]: ./src/plugins/mocha
543
+ [23]: ./src/plugins/next
544
+ [24]: ./src/plugins/npm-package-json-lint
545
+ [25]: ./src/plugins/nx
546
+ [26]: ./src/plugins/nyc
547
+ [27]: ./src/plugins/playwright
548
+ [28]: ./src/plugins/postcss
549
+ [29]: ./src/plugins/prettier
550
+ [30]: ./src/plugins/release-it
551
+ [31]: ./src/plugins/remark
552
+ [32]: ./src/plugins/remix
553
+ [33]: ./src/plugins/rollup
554
+ [34]: ./src/plugins/sentry
555
+ [35]: ./src/plugins/storybook
556
+ [36]: ./src/plugins/stryker
557
+ [37]: ./src/plugins/typescript
558
+ [38]: ./src/plugins/webpack
559
+ [39]: #config
560
+ [40]: #code-owners
561
+ [41]: #compact
562
+ [42]: #json
563
+ [43]: #symbol-default
564
+ [44]: ./docs/custom-reporters.md
565
+ [45]: #create-a-new-plugin
566
+ [46]: #libraries-and-unused-exports
567
+ [47]: https://github.com/depcheck/depcheck
568
+ [48]: https://github.com/smeijer/unimported
569
+ [49]: https://github.com/pzavolinsky/ts-unused-exports
570
+ [50]: https://github.com/nadeesha/ts-prune
571
+ [51]: #workspaces--monorepos
572
+ [52]: #production-mode
@@ -1,4 +1,3 @@
1
- import { EOL } from 'os';
2
1
  import { getBinariesFromScripts } from '../../util/binaries/index.js';
3
2
  import { _firstGlob } from '../../util/glob.js';
4
3
  import { _load } from '../../util/loader.js';
@@ -14,7 +13,7 @@ const findGithubActionsDependencies = async (configFilePath, { manifest, rootCon
14
13
  return [];
15
14
  const scripts = getValuesByKeyDeep(config, 'run')
16
15
  .filter((value) => typeof value === 'string')
17
- .flatMap(script => script.split(EOL))
16
+ .flatMap(script => script.split('\n'))
18
17
  .map(script => script.trim());
19
18
  const binaries = getBinariesFromScripts(scripts, {
20
19
  manifest,
@@ -0,0 +1,6 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "husky";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,25 @@
1
+ import { readFileSync } from 'fs';
2
+ import { getBinariesFromScripts } from '../../util/binaries/index.js';
3
+ import { timerify } from '../../util/performance.js';
4
+ import { hasDependency } from '../../util/plugin.js';
5
+ export const NAME = 'husky';
6
+ export const ENABLERS = ['husky'];
7
+ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
+ export const CONFIG_FILE_PATTERNS = [
9
+ '.husky/commit-msg',
10
+ '.husky/pre-{applypatch,commit,merge-commit,push,rebase,receive}',
11
+ '.husky/post-{checkout,commit,merge,rewrite}',
12
+ ];
13
+ const findHuskyDependencies = async (configFilePath, { manifest, rootConfig }) => {
14
+ const script = readFileSync(configFilePath);
15
+ const scripts = String(script)
16
+ .split('\n')
17
+ .map(script => script.trim());
18
+ const binaries = getBinariesFromScripts(scripts, {
19
+ manifest,
20
+ ignore: rootConfig.ignoreBinaries,
21
+ knownGlobalsOnly: true,
22
+ });
23
+ return binaries;
24
+ };
25
+ export const findDependencies = timerify(findHuskyDependencies);
@@ -6,6 +6,7 @@ export * as cypress from './cypress/index.js';
6
6
  export * as eslint from './eslint/index.js';
7
7
  export * as gatsby from './gatsby/index.js';
8
8
  export * as githubActions from './github-actions/index.js';
9
+ export * as husky from './husky/index.js';
9
10
  export * as jest from './jest/index.js';
10
11
  export * as lintStaged from './lint-staged/index.js';
11
12
  export * as markdownlint from './markdownlint/index.js';
@@ -6,6 +6,7 @@ export * as cypress from './cypress/index.js';
6
6
  export * as eslint from './eslint/index.js';
7
7
  export * as gatsby from './gatsby/index.js';
8
8
  export * as githubActions from './github-actions/index.js';
9
+ export * as husky from './husky/index.js';
9
10
  export * as jest from './jest/index.js';
10
11
  export * as lintStaged from './lint-staged/index.js';
11
12
  export * as markdownlint from './markdownlint/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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",
package/schema.json CHANGED
@@ -188,6 +188,10 @@
188
188
  "title": "github-actions plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/github-actions/README.md)",
189
189
  "$ref": "#/definitions/plugin"
190
190
  },
191
+ "husky": {
192
+ "title": "husky plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/husky/README.md)",
193
+ "$ref": "#/definitions/plugin"
194
+ },
191
195
  "jest": {
192
196
  "title": "Jest plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/jest/README.md)",
193
197
  "$ref": "#/definitions/plugin"