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 +67 -65
- package/dist/plugins/github-actions/index.js +1 -2
- package/dist/plugins/husky/index.d.ts +6 -0
- package/dist/plugins/husky/index.js +25 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/package.json +1 -1
- package/schema.json +4 -0
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
|
-
- [
|
|
238
|
-
- [
|
|
239
|
-
- [
|
|
240
|
-
- [
|
|
241
|
-
- [
|
|
242
|
-
- [
|
|
243
|
-
- [
|
|
244
|
-
- [
|
|
245
|
-
- [
|
|
246
|
-
- [
|
|
247
|
-
- [
|
|
248
|
-
- [
|
|
249
|
-
- [
|
|
250
|
-
- [
|
|
251
|
-
- [
|
|
252
|
-
- [
|
|
253
|
-
- [
|
|
254
|
-
- [
|
|
255
|
-
- [
|
|
256
|
-
- [
|
|
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][
|
|
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`][
|
|
345
|
-
- [`compact`][
|
|
346
|
-
- [`json`][
|
|
347
|
-
- [`symbol`][
|
|
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][
|
|
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][
|
|
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][
|
|
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][
|
|
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][
|
|
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][
|
|
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/
|
|
538
|
-
[19]: ./src/plugins/
|
|
539
|
-
[20]: ./src/plugins/
|
|
540
|
-
[21]: ./src/plugins/
|
|
541
|
-
[22]: ./src/plugins/
|
|
542
|
-
[23]: ./src/plugins/
|
|
543
|
-
[24]: ./src/plugins/
|
|
544
|
-
[25]: ./src/plugins/
|
|
545
|
-
[26]: ./src/plugins/
|
|
546
|
-
[27]: ./src/plugins/
|
|
547
|
-
[28]: ./src/plugins/
|
|
548
|
-
[29]: ./src/plugins/
|
|
549
|
-
[30]: ./src/plugins/
|
|
550
|
-
[31]: ./src/plugins/
|
|
551
|
-
[32]: ./src/plugins/
|
|
552
|
-
[33]: ./src/plugins/
|
|
553
|
-
[34]: ./src/plugins/
|
|
554
|
-
[35]: ./src/plugins/
|
|
555
|
-
[36]: ./src/plugins/
|
|
556
|
-
[37]: ./src/plugins/
|
|
557
|
-
[38]:
|
|
558
|
-
[39]: #
|
|
559
|
-
[40]: #
|
|
560
|
-
[41]: #
|
|
561
|
-
[42]: #
|
|
562
|
-
[43]:
|
|
563
|
-
[44]:
|
|
564
|
-
[45]: #
|
|
565
|
-
[46]:
|
|
566
|
-
[47]: https://github.com/
|
|
567
|
-
[48]: https://github.com/
|
|
568
|
-
[49]: https://github.com/
|
|
569
|
-
[50]:
|
|
570
|
-
[51]: #
|
|
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(
|
|
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);
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -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/dist/plugins/index.js
CHANGED
|
@@ -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
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"
|