knip 2.0.0-alpha.1 → 2.0.0-alpha.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 +46 -49
- package/dist/configuration-chief.js +3 -3
- package/dist/constants.js +5 -1
- package/dist/plugins/jest/index.d.ts +1 -1
- package/dist/plugins/jest/index.js +1 -1
- package/dist/plugins/mocha/index.d.ts +1 -1
- package/dist/plugins/mocha/index.js +1 -1
- package/dist/plugins/playwright/index.js +1 -1
- package/dist/plugins/typedoc/index.js +1 -1
- package/dist/plugins/typedoc/types.d.ts +1 -1
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -196,8 +196,8 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
196
196
|
|
|
197
197
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
198
198
|
|
|
199
|
-
Still not happy with the results? Getting too much output/false positives? The [FAQ][
|
|
200
|
-
an issue and I'm happy to look into it. Also see the next section on how to [ignore][11] certain false positives:
|
|
199
|
+
Still not happy with the results? Getting too much output/false positives? The [FAQ][10] may be useful. Feel free to
|
|
200
|
+
open an issue and I'm happy to look into it. Also see the next section on how to [ignore][11] certain false positives:
|
|
201
201
|
|
|
202
202
|
## Ignore
|
|
203
203
|
|
|
@@ -345,6 +345,14 @@ rest to find which of those dependencies are unused or missing.
|
|
|
345
345
|
Other configuration files use `require` or `import` statements to use dependencies, so they can be analyzed like the
|
|
346
346
|
rest of the source files. These configuration files are also considered `entry` files.
|
|
347
347
|
|
|
348
|
+
For plugins related to test files, it's good to know that the following glob patterns are always included by default:
|
|
349
|
+
|
|
350
|
+
- `**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}`
|
|
351
|
+
- `**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs}`
|
|
352
|
+
- `**/test/**/*.{js,jsx,ts,tsx,mjs,cjs}`
|
|
353
|
+
|
|
354
|
+
Files matching these patterns are excluded in [production mode][45].
|
|
355
|
+
|
|
348
356
|
### Disable a plugin
|
|
349
357
|
|
|
350
358
|
In case a plugin causes issues, it can be disabled by using `false` as its value (e.g. `"webpack": false`).
|
|
@@ -440,10 +448,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
|
|
|
440
448
|
|
|
441
449
|
Knip provides the following built-in reporters:
|
|
442
450
|
|
|
443
|
-
-
|
|
444
|
-
-
|
|
445
|
-
-
|
|
446
|
-
-
|
|
451
|
+
- codeowners
|
|
452
|
+
- compact
|
|
453
|
+
- json
|
|
454
|
+
- symbol
|
|
447
455
|
|
|
448
456
|
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
449
457
|
|
|
@@ -470,13 +478,12 @@ type ReporterOptions = {
|
|
|
470
478
|
|
|
471
479
|
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
472
480
|
|
|
473
|
-
Find more details and ideas in [custom reporters][
|
|
481
|
+
Find more details and ideas in [custom reporters][46].
|
|
474
482
|
|
|
475
|
-
##
|
|
483
|
+
## Public exports
|
|
476
484
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
in libraries can be marked with the JSDoc `@public` tag:
|
|
485
|
+
Sometimes a file that's not an entry file has one or more exports that are public, and should not be reported as unused.
|
|
486
|
+
Such variables and types can be marked with the JSDoc `@public` tag:
|
|
480
487
|
|
|
481
488
|
```js
|
|
482
489
|
/**
|
|
@@ -528,7 +535,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
|
|
|
528
535
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
529
536
|
to match the custom location(s).
|
|
530
537
|
|
|
531
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
538
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][47].
|
|
532
539
|
|
|
533
540
|
#### Too many unused exports
|
|
534
541
|
|
|
@@ -536,7 +543,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
536
543
|
|
|
537
544
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
538
545
|
add the containing file to the `entry` array in the configuration.
|
|
539
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
546
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][48]
|
|
540
547
|
|
|
541
548
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
542
549
|
|
|
@@ -556,22 +563,23 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
556
563
|
|
|
557
564
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
558
565
|
|
|
559
|
-
| Feature
|
|
560
|
-
|
|
|
561
|
-
| Unused files
|
|
562
|
-
| Unused dependencies
|
|
563
|
-
| Unlisted dependencies
|
|
564
|
-
| [Plugins][
|
|
565
|
-
|
|
|
566
|
-
| Unused
|
|
567
|
-
| Unused
|
|
568
|
-
|
|
|
569
|
-
|
|
|
570
|
-
|
|
|
571
|
-
|
|
|
572
|
-
|
|
|
573
|
-
|
|
|
574
|
-
|
|
|
566
|
+
| Feature | **knip** | [depcheck][49] | [unimported][50] | [ts-unused-exports][51] | [ts-prune][52] |
|
|
567
|
+
| :-------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
568
|
+
| Unused files | ✅ | - | ✅ | - | - |
|
|
569
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
570
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - |
|
|
571
|
+
| [Plugins][2] | ✅ | ✅ | ❌ | - | - |
|
|
572
|
+
| [Compilers][3] | ✅ | - | - | - | - |
|
|
573
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ |
|
|
574
|
+
| Unused class members | ✅ | - | - | - | - |
|
|
575
|
+
| Unused enum members | ✅ | - | - | - | - |
|
|
576
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ |
|
|
577
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ |
|
|
578
|
+
| Custom reporters | ✅ | - | - | - | - |
|
|
579
|
+
| JavaScript support | ✅ | ✅ | ✅ | - | - |
|
|
580
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
581
|
+
| [Support workspaces/monorepos][1] | ✅ | ❌ | ❌ | - | - |
|
|
582
|
+
| ESLint plugin available | - | - | - | ✅ | - |
|
|
575
583
|
|
|
576
584
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
577
585
|
|
|
@@ -591,7 +599,7 @@ The following commands are similar:
|
|
|
591
599
|
unimported
|
|
592
600
|
knip --production --dependencies --include files
|
|
593
601
|
|
|
594
|
-
Also see [production mode][
|
|
602
|
+
Also see [production mode][45].
|
|
595
603
|
|
|
596
604
|
### ts-unused-exports
|
|
597
605
|
|
|
@@ -609,13 +617,6 @@ The following commands are similar:
|
|
|
609
617
|
knip --include exports,types
|
|
610
618
|
knip --exports # Adds unused exports/types in namespaces and unused enum/class members
|
|
611
619
|
|
|
612
|
-
## TypeScript language services
|
|
613
|
-
|
|
614
|
-
TypeScript language services could play a major role in most of the "unused" areas, as they have an overview of the
|
|
615
|
-
project as a whole. This powers things in VS Code like "Find references" or the "Module "./some" declares 'Thing'
|
|
616
|
-
locally, but it is not exported" message. I think features like "duplicate exports" or "custom dependency resolvers" are
|
|
617
|
-
userland territory, much like code linters.
|
|
618
|
-
|
|
619
620
|
## Knip?!
|
|
620
621
|
|
|
621
622
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
@@ -665,15 +666,11 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
665
666
|
[42]: ./src/plugins/vitest
|
|
666
667
|
[43]: ./src/plugins/webpack
|
|
667
668
|
[44]: #config
|
|
668
|
-
[45]: #
|
|
669
|
-
[46]:
|
|
670
|
-
[47]: #
|
|
671
|
-
[48]: #
|
|
672
|
-
[49]:
|
|
673
|
-
[50]:
|
|
674
|
-
[51]:
|
|
675
|
-
[52]: https://github.com/
|
|
676
|
-
[53]: https://github.com/smeijer/unimported
|
|
677
|
-
[54]: https://github.com/pzavolinsky/ts-unused-exports
|
|
678
|
-
[55]: https://github.com/nadeesha/ts-prune
|
|
679
|
-
[56]: #production-mode
|
|
669
|
+
[45]: #production-mode
|
|
670
|
+
[46]: ./docs/custom-reporters.md
|
|
671
|
+
[47]: #create-a-new-plugin
|
|
672
|
+
[48]: #public-exports
|
|
673
|
+
[49]: https://github.com/depcheck/depcheck
|
|
674
|
+
[50]: https://github.com/smeijer/unimported
|
|
675
|
+
[51]: https://github.com/pzavolinsky/ts-unused-exports
|
|
676
|
+
[52]: https://github.com/nadeesha/ts-prune
|
|
@@ -17,10 +17,10 @@ import { resolveIncludedIssueTypes } from './util/resolve-included-issue-types.j
|
|
|
17
17
|
import { byPathDepth } from './util/workspace.js';
|
|
18
18
|
const { config: rawConfigArg, workspace: rawWorkspaceArg, include = [], exclude = [], dependencies = false, exports = false, } = parsedArgs.values;
|
|
19
19
|
const getDefaultWorkspaceConfig = (extensions) => {
|
|
20
|
-
const
|
|
20
|
+
const exts = [...DEFAULT_EXTENSIONS, ...(extensions ?? [])].map(ext => ext.slice(1)).join(',');
|
|
21
21
|
return {
|
|
22
|
-
entry: [`index.{${
|
|
23
|
-
project: [`**/*.{${
|
|
22
|
+
entry: [`index.{${exts}}!`, `src/index.{${exts}}!`],
|
|
23
|
+
project: [`**/*.{${exts}}!`],
|
|
24
24
|
paths: {},
|
|
25
25
|
ignore: [],
|
|
26
26
|
ignoreBinaries: [],
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export const ROOT_WORKSPACE_NAME = '.';
|
|
2
2
|
export const KNIP_CONFIG_LOCATIONS = ['knip.json', 'knip.jsonc', '.knip.json', '.knip.jsonc', 'knip.ts', 'knip.js'];
|
|
3
3
|
export const DEFAULT_EXTENSIONS = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx'];
|
|
4
|
-
export const TEST_FILE_PATTERNS = [
|
|
4
|
+
export const TEST_FILE_PATTERNS = [
|
|
5
|
+
'**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs}',
|
|
6
|
+
'**/__tests__/**/*.{js,jsx,ts,tsx,mjs,cjs}',
|
|
7
|
+
'**/test/**/*.{js,jsx,ts,tsx,mjs,cjs}',
|
|
8
|
+
];
|
|
5
9
|
export const IGNORED_GLOBAL_BINARIES = [
|
|
6
10
|
'bun',
|
|
7
11
|
'deno',
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Jest";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -9,7 +9,7 @@ export const NAME = 'Jest';
|
|
|
9
9
|
export const ENABLERS = ['jest'];
|
|
10
10
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
11
11
|
export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}'];
|
|
12
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
12
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
13
13
|
const join = (base, id) => (isAbsolute(id) ? id : path.join(path.dirname(base), id));
|
|
14
14
|
const resolveExtensibleConfig = async (configFilePath) => {
|
|
15
15
|
const config = await _load(configFilePath);
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Mocha";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -6,7 +6,7 @@ export const NAME = 'Mocha';
|
|
|
6
6
|
export const ENABLERS = ['mocha'];
|
|
7
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
8
|
export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
|
|
9
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
9
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
10
10
|
const findMochaDependencies = async (configFilePath, { manifest }) => {
|
|
11
11
|
const config = configFilePath.endsWith('package.json') ? manifest.mocha : await _load(configFilePath);
|
|
12
12
|
if (config) {
|
|
@@ -2,4 +2,4 @@ import { hasDependency } from '../../util/plugin.js';
|
|
|
2
2
|
export const NAME = 'Playwright';
|
|
3
3
|
export const ENABLERS = ['@playwright/test'];
|
|
4
4
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
5
|
-
export const ENTRY_FILE_PATTERNS = ['playwright.config.{js,ts}'
|
|
5
|
+
export const ENTRY_FILE_PATTERNS = ['playwright.config.{js,ts}'];
|
|
@@ -12,6 +12,6 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
];
|
|
13
13
|
const findPluginDependencies = async (configFilePath) => {
|
|
14
14
|
const config = await _load(configFilePath);
|
|
15
|
-
return config?.
|
|
15
|
+
return config?.plugin ?? [];
|
|
16
16
|
};
|
|
17
17
|
export const findDependencies = timerify(findPluginDependencies);
|
|
@@ -3,5 +3,5 @@ export declare const NAME = "Vitest";
|
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
|
-
export declare const ENTRY_FILE_PATTERNS:
|
|
6
|
+
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
7
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -7,7 +7,7 @@ export const NAME = 'Vitest';
|
|
|
7
7
|
export const ENABLERS = ['vitest'];
|
|
8
8
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
9
9
|
export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vite.config.ts'];
|
|
10
|
-
export const ENTRY_FILE_PATTERNS = [
|
|
10
|
+
export const ENTRY_FILE_PATTERNS = [];
|
|
11
11
|
const findVitestDependencies = async (configFilePath) => {
|
|
12
12
|
const config = await _load(configFilePath);
|
|
13
13
|
if (!config || !config.test)
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.0.0-alpha.
|
|
1
|
+
export declare const version = "2.0.0-alpha.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.0.0-alpha.
|
|
1
|
+
export const version = '2.0.0-alpha.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"lint": "eslint src",
|
|
23
23
|
"lint:fix": "eslint src --fix",
|
|
24
24
|
"format": "prettier scripts src test --with-node-modules --write --config .prettierrc",
|
|
25
|
-
"test": "globstar -- node --loader tsx --test \"
|
|
25
|
+
"test": "globstar -- node --loader tsx --test \"tests/**/*.test.ts\"",
|
|
26
26
|
"watch": "tsc --watch",
|
|
27
27
|
"prebuild": "rm -rf dist",
|
|
28
28
|
"build": "tsc",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"docs:cli": "tsx ./scripts/update-cli-usage-in-readme.ts",
|
|
31
31
|
"docs:plugins": "tsx ./scripts/generate-plugin-docs.ts",
|
|
32
32
|
"docs:format": "remark README.md docs/*.md src/plugins/*/README.md -o",
|
|
33
|
+
"qa": "npm run lint && npm run build && npm run knip && npm run knip:production && npm test",
|
|
33
34
|
"release": "release-it",
|
|
34
35
|
"create-plugin": "tsx ./scripts/create-new-plugin.ts"
|
|
35
36
|
},
|
|
@@ -57,24 +58,24 @@
|
|
|
57
58
|
"zod": "^3.20.6"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@jest/types": "29.
|
|
61
|
+
"@jest/types": "29.5.0",
|
|
61
62
|
"@npmcli/package-json": "3.0.0",
|
|
62
63
|
"@release-it/bumper": "4.0.2",
|
|
63
64
|
"@types/eslint": "8.21.1",
|
|
64
65
|
"@types/js-yaml": "4.0.5",
|
|
65
66
|
"@types/micromatch": "4.0.2",
|
|
66
67
|
"@types/minimist": "1.2.2",
|
|
67
|
-
"@types/node": "18.14.
|
|
68
|
+
"@types/node": "18.14.6",
|
|
68
69
|
"@types/npmcli__map-workspaces": "3.0.0",
|
|
69
70
|
"@types/webpack": "5.28.0",
|
|
70
|
-
"@typescript-eslint/eslint-plugin": "5.54.
|
|
71
|
-
"@typescript-eslint/parser": "5.54.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "5.54.1",
|
|
72
|
+
"@typescript-eslint/parser": "5.54.1",
|
|
72
73
|
"eslint": "8.35.0",
|
|
73
74
|
"eslint-import-resolver-typescript": "3.5.3",
|
|
74
75
|
"eslint-plugin-import": "2.27.5",
|
|
75
76
|
"globstar": "1.0.0",
|
|
76
77
|
"prettier": "2.8.4",
|
|
77
|
-
"release-it": "^15.
|
|
78
|
+
"release-it": "^15.7.0",
|
|
78
79
|
"remark-cli": "11.0.0",
|
|
79
80
|
"remark-preset-webpro": "0.0.1",
|
|
80
81
|
"tsx": "3.12.3",
|