knip 5.44.5 → 5.46.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 +3 -3
- package/dist/ConfigurationChief.d.ts +1 -0
- package/dist/ConfigurationChief.js +6 -0
- package/dist/IssueCollector.js +2 -1
- package/dist/IssueFixer.js +1 -1
- package/dist/WorkspaceWorker.d.ts +6 -1
- package/dist/WorkspaceWorker.js +49 -28
- package/dist/binaries/bash-parser.js +2 -1
- package/dist/binaries/package-manager/bun.js +7 -3
- package/dist/binaries/package-manager/yarn.js +5 -4
- package/dist/binaries/plugins.js +23 -20
- package/dist/cli.js +6 -4
- package/dist/compilers/index.d.ts +1 -0
- package/dist/graph/analyze.d.ts +1 -1
- package/dist/graph/analyze.js +2 -2
- package/dist/graph/build.js +9 -12
- package/dist/index.js +5 -4
- package/dist/plugins/angular/index.js +2 -2
- package/dist/plugins/eslint/helpers.d.ts +2 -2
- package/dist/plugins/eslint/helpers.js +14 -6
- package/dist/plugins/eslint/index.d.ts +5 -2
- package/dist/plugins/eslint/index.js +31 -3
- package/dist/plugins/eslint/types.d.ts +5 -4
- package/dist/plugins/index.d.ts +1 -7
- package/dist/plugins/playwright/index.d.ts +0 -6
- package/dist/plugins/playwright/index.js +1 -1
- package/dist/plugins/playwright-ct/index.d.ts +0 -6
- package/dist/plugins/playwright-ct/index.js +1 -2
- package/dist/plugins/storybook/index.js +2 -2
- package/dist/plugins/typescript/index.js +4 -2
- package/dist/plugins/xo/index.js +2 -2
- package/dist/plugins/xo/types.d.ts +2 -2
- package/dist/reporters/codeclimate.d.ts +3 -0
- package/dist/reporters/codeclimate.js +87 -0
- package/dist/reporters/compact.js +1 -1
- package/dist/reporters/disclosure.js +11 -24
- package/dist/reporters/index.d.ts +2 -1
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/symbols.d.ts +1 -1
- package/dist/reporters/symbols.js +15 -32
- package/dist/schema/configuration.d.ts +3 -0
- package/dist/schema/configuration.js +1 -0
- package/dist/types/cli.d.ts +1 -1
- package/dist/types/config.d.ts +2 -1
- package/dist/types/issues.d.ts +4 -3
- package/dist/typescript/SourceFile.d.ts +0 -1
- package/dist/typescript/find-internal-references.js +9 -2
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +3 -1
- package/dist/util/get-referenced-inputs.js +2 -2
- package/dist/util/input.d.ts +3 -3
- package/dist/util/input.js +5 -5
- package/dist/util/issue-initializers.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
- package/schema.json +5 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { isIdChar } from '../util/regex.js';
|
|
3
3
|
export const isType = (item) => item.type === 'type' || item.type === 'interface' || item.type === 'enum';
|
|
4
|
+
const findInFlow = (flowNode, targetSymbol) => {
|
|
5
|
+
if (!flowNode?.node)
|
|
6
|
+
return false;
|
|
7
|
+
if (flowNode.node.symbol === targetSymbol)
|
|
8
|
+
return true;
|
|
9
|
+
return findInFlow(flowNode.antecedent, targetSymbol);
|
|
10
|
+
};
|
|
4
11
|
export const findInternalReferences = (item, sourceFile, typeChecker, referencedSymbolsInExport, isBindingElement) => {
|
|
5
12
|
if (!item.symbol)
|
|
6
13
|
return [0, false];
|
|
@@ -19,7 +26,7 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
19
26
|
const isExportDeclaration = index === item.pos || index === item.pos + 1;
|
|
20
27
|
if (!isExportDeclaration) {
|
|
21
28
|
const symbol = typeChecker.getSymbolAtLocation(ts.getTokenAtPosition(sourceFile, index));
|
|
22
|
-
if (symbol) {
|
|
29
|
+
if (symbol && id === symbol.escapedName) {
|
|
23
30
|
const isInExport = referencedSymbolsInExport.has(symbol);
|
|
24
31
|
if (isInExport)
|
|
25
32
|
isSymbolInExport = true;
|
|
@@ -30,7 +37,7 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
30
37
|
}
|
|
31
38
|
const declaration = symbol.declarations?.[0];
|
|
32
39
|
if (declaration) {
|
|
33
|
-
if (
|
|
40
|
+
if (findInFlow(declaration.name?.flowNode, item.symbol)) {
|
|
34
41
|
return [++refCount, isSymbolInExport];
|
|
35
42
|
}
|
|
36
43
|
if (ts.isImportSpecifier(declaration) && symbols.has(symbol)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
1
|
+
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
cache?: boolean | undefined;
|
|
4
4
|
'cache-location'?: string | undefined;
|
|
@@ -35,6 +35,7 @@ declare const _default: {
|
|
|
35
35
|
trace?: boolean | undefined;
|
|
36
36
|
'trace-export'?: string | undefined;
|
|
37
37
|
'trace-file'?: string | undefined;
|
|
38
|
+
'treat-config-hints-as-errors'?: boolean | undefined;
|
|
38
39
|
tsConfig?: string | undefined;
|
|
39
40
|
version?: boolean | undefined;
|
|
40
41
|
watch?: boolean | undefined;
|
|
@@ -28,10 +28,11 @@ Options:
|
|
|
28
28
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
29
29
|
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
30
30
|
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
|
|
31
|
-
--reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
|
|
31
|
+
--reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, can be repeated (default: symbols)
|
|
32
32
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
33
33
|
--tags Include or exclude tagged exports
|
|
34
34
|
--no-config-hints Suppress configuration hints
|
|
35
|
+
--treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints
|
|
35
36
|
--no-exit-code Always exit with code zero (0)
|
|
36
37
|
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
37
38
|
-d, --debug Show debug output
|
|
@@ -94,6 +95,7 @@ try {
|
|
|
94
95
|
trace: { type: 'boolean' },
|
|
95
96
|
'trace-export': { type: 'string' },
|
|
96
97
|
'trace-file': { type: 'string' },
|
|
98
|
+
'treat-config-hints-as-errors': { type: 'boolean' },
|
|
97
99
|
tsConfig: { type: 'string', short: 't' },
|
|
98
100
|
version: { type: 'boolean', short: 'V' },
|
|
99
101
|
watch: { type: 'boolean' },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IGNORED_RUNTIME_DEPENDENCIES } from '../constants.js';
|
|
2
2
|
import { debugLog } from './debug.js';
|
|
3
3
|
import { isDeferResolve, toDebugString } from './input.js';
|
|
4
|
-
import { fromBinary, isBinary,
|
|
4
|
+
import { fromBinary, isBinary, isConfig, isDeferResolveEntry, isDependency } from './input.js';
|
|
5
5
|
import { getPackageNameFromSpecifier } from './modules.js';
|
|
6
6
|
import { dirname, isAbsolute, isInternal, join } from './path.js';
|
|
7
7
|
import { _resolveSync } from './resolve.js';
|
|
@@ -75,7 +75,7 @@ export const getReferencedInputsHandler = (collector, deputy, chief, isGitIgnore
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
else if (!isGitIgnored(filePath)) {
|
|
78
|
-
if (!isDeferResolveEntry(input) && !
|
|
78
|
+
if (!isDeferResolveEntry(input) && !isConfig(input)) {
|
|
79
79
|
collector.addIssue({
|
|
80
80
|
type: 'unresolved',
|
|
81
81
|
filePath: containingFilePath,
|
package/dist/util/input.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface Input {
|
|
|
10
10
|
}
|
|
11
11
|
export interface ConfigInput extends Input {
|
|
12
12
|
type: 'config';
|
|
13
|
-
containingFilePath
|
|
13
|
+
containingFilePath?: string;
|
|
14
14
|
pluginName: PluginName;
|
|
15
15
|
}
|
|
16
16
|
type Options = {
|
|
@@ -25,8 +25,8 @@ export declare const toEntry: (specifier: string) => Input;
|
|
|
25
25
|
export declare const isEntry: (input: Input) => boolean;
|
|
26
26
|
export declare const toProductionEntry: (specifier: string, options?: Options) => Input;
|
|
27
27
|
export declare const isProductionEntry: (input: Input) => boolean;
|
|
28
|
-
export declare const toConfig: (pluginName: PluginName, specifier: string,
|
|
29
|
-
export declare const
|
|
28
|
+
export declare const toConfig: (pluginName: PluginName, specifier: string, options?: Options) => ConfigInput;
|
|
29
|
+
export declare const isConfig: (input: Input) => input is ConfigInput;
|
|
30
30
|
export declare const toDependency: (specifier: string, options?: Options) => Input;
|
|
31
31
|
export declare const isDependency: (input: Input) => boolean;
|
|
32
32
|
export declare const toProductionDependency: (specifier: string) => Input;
|
package/dist/util/input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toRelative } from './path.js';
|
|
1
|
+
import { isAbsolute, toRelative } from './path.js';
|
|
2
2
|
export const fromBinary = (input) => input.specifier;
|
|
3
3
|
export const toBinary = (specifier, options = {}) => ({
|
|
4
4
|
type: 'binary',
|
|
@@ -15,13 +15,13 @@ export const toProductionEntry = (specifier, options = {}) => ({
|
|
|
15
15
|
...options,
|
|
16
16
|
});
|
|
17
17
|
export const isProductionEntry = (input) => input.type === 'entry' && input.production === true;
|
|
18
|
-
export const toConfig = (pluginName, specifier,
|
|
18
|
+
export const toConfig = (pluginName, specifier, options = {}) => ({
|
|
19
19
|
type: 'config',
|
|
20
20
|
specifier,
|
|
21
21
|
pluginName,
|
|
22
|
-
|
|
22
|
+
...options,
|
|
23
23
|
});
|
|
24
|
-
export const
|
|
24
|
+
export const isConfig = (input) => input.type === 'config';
|
|
25
25
|
export const toDependency = (specifier, options = {}) => ({
|
|
26
26
|
type: 'dependency',
|
|
27
27
|
specifier,
|
|
@@ -44,4 +44,4 @@ export const toDeferResolveProductionEntry = (specifier) => ({
|
|
|
44
44
|
export const isDeferResolveProductionEntry = (input) => input.type === 'deferResolveEntry' && input.production === true;
|
|
45
45
|
export const toDeferResolveEntry = (specifier) => ({ type: 'deferResolveEntry', specifier });
|
|
46
46
|
export const isDeferResolveEntry = (input) => input.type === 'deferResolveEntry';
|
|
47
|
-
export const toDebugString = (input) => `${input.type}:${input.specifier}${input.containingFilePath ? ` (${toRelative(input.containingFilePath)})` : ''}`;
|
|
47
|
+
export const toDebugString = (input) => `${input.type}:${isAbsolute(input.specifier) ? toRelative(input.specifier) : input.specifier}${input.containingFilePath ? ` (${toRelative(input.containingFilePath)})` : ''}`;
|
|
@@ -2,7 +2,7 @@ import { ISSUE_TYPES } from '../constants.js';
|
|
|
2
2
|
export const initIssues = () => ({
|
|
3
3
|
...Object.fromEntries(ISSUE_TYPES.map(issueType => [issueType, {}])),
|
|
4
4
|
files: new Set(),
|
|
5
|
-
_files:
|
|
5
|
+
_files: {},
|
|
6
6
|
});
|
|
7
7
|
export const initCounters = () => ({
|
|
8
8
|
...Object.fromEntries(ISSUE_TYPES.map(issueType => [issueType, 0])),
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.46.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.46.0';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.46.0",
|
|
4
4
|
"description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://knip.dev",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/webpro-nl/knip",
|
|
8
|
+
"url": "git+https://github.com/webpro-nl/knip.git",
|
|
9
9
|
"directory": "packages/knip"
|
|
10
10
|
},
|
|
11
11
|
"bugs": "https://github.com/webpro-nl/knip/issues",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
],
|
|
31
31
|
"main": "./dist/index.js",
|
|
32
32
|
"bin": {
|
|
33
|
-
"knip": "
|
|
34
|
-
"knip-bun": "
|
|
33
|
+
"knip": "bin/knip.js",
|
|
34
|
+
"knip-bun": "bin/knip-bun.js"
|
|
35
35
|
},
|
|
36
36
|
"type": "module",
|
|
37
37
|
"types": "./dist/index.d.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"qa": "bun lint && bun run build && bun knip && bun knip:production && bun run test",
|
|
50
50
|
"release": "release-it",
|
|
51
51
|
"create-plugin": "bun ./scripts/create-new-plugin.ts",
|
|
52
|
-
"postcreate-plugin": "bun run build && biome format --write schema.json schema-jsonc.json src/
|
|
52
|
+
"postcreate-plugin": "bun run build && biome format --write schema.json schema-jsonc.json src/schema/plugins.ts",
|
|
53
53
|
"generate-plugin-defs": "node ./scripts/generate-plugin-defs.js && biome check --write src/plugins/index.ts src/types/PluginNames.ts src/schema/plugins.ts"
|
|
54
54
|
},
|
|
55
55
|
"files": [
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@types/webpack": "^5.28.5",
|
|
91
91
|
"@wdio/types": "^9.5.0",
|
|
92
92
|
"glob": "^10.4.2",
|
|
93
|
-
"release-it": "^
|
|
93
|
+
"release-it": "^19.0.0-next.1",
|
|
94
94
|
"type-fest": "^4.31.0",
|
|
95
95
|
"typescript": "^5.5.2"
|
|
96
96
|
},
|
package/schema.json
CHANGED
|
@@ -102,6 +102,11 @@
|
|
|
102
102
|
"title": "Include entry files when reporting unused exports",
|
|
103
103
|
"type": "boolean"
|
|
104
104
|
},
|
|
105
|
+
"tags": {
|
|
106
|
+
"title": "Exclude (-) or include (+) exports with the specified JSDoc/TSDoc tags",
|
|
107
|
+
"examples": ["+custom", "-lintignore", "-@internal"],
|
|
108
|
+
"$ref": "#/definitions/list"
|
|
109
|
+
},
|
|
105
110
|
"workspaces": {
|
|
106
111
|
"title": "Configuration for workspaces",
|
|
107
112
|
"type": "object",
|