knip 5.43.2 → 5.43.4
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/dist/index.js +3 -3
- package/dist/plugins/jest/index.js +1 -1
- package/dist/typescript/ast-helpers.d.ts +1 -1
- package/dist/typescript/ast-helpers.js +2 -4
- package/dist/typescript/get-imports-and-exports.js +18 -14
- package/dist/util/has-strictly-ns-references.d.ts +2 -1
- package/dist/util/has-strictly-ns-references.js +31 -23
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getOrCreateFileNode, updateImportMap } from './util/dependency-graph.js
|
|
|
13
13
|
import { getReferencedInputsHandler } from './util/get-referenced-inputs.js';
|
|
14
14
|
import { getGitIgnoredHandler } from './util/glob-core.js';
|
|
15
15
|
import { _glob, negate } from './util/glob.js';
|
|
16
|
-
import {
|
|
16
|
+
import { getType, hasStrictlyEnumReferences, hasStrictlyNsReferences } from './util/has-strictly-ns-references.js';
|
|
17
17
|
import { isConfigPattern, isEntry, isProductionEntry, toProductionEntry } from './util/input.js';
|
|
18
18
|
import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
|
|
19
19
|
import { getPackageNameFromModuleSpecifier } from './util/modules.js';
|
|
@@ -358,7 +358,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
358
358
|
printTrace(traceNode, filePath, identifier);
|
|
359
359
|
if (isReferenced) {
|
|
360
360
|
if (report.enumMembers && exportedItem.type === 'enum') {
|
|
361
|
-
if (importsForExport
|
|
361
|
+
if (hasStrictlyEnumReferences(importsForExport, identifier))
|
|
362
362
|
continue;
|
|
363
363
|
for (const member of exportedItem.members) {
|
|
364
364
|
if (findMatch(workspace.ignoreMembers, member.identifier))
|
|
@@ -424,7 +424,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
424
424
|
continue;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
const [hasStrictlyNsRefs, namespace] =
|
|
427
|
+
const [hasStrictlyNsRefs, namespace] = hasStrictlyNsReferences(graph, importsForExport, identifier);
|
|
428
428
|
const isType = ['enum', 'type', 'interface'].includes(exportedItem.type);
|
|
429
429
|
if (hasStrictlyNsRefs && ((!report.nsTypes && isType) || !(report.nsExports || isType)))
|
|
430
430
|
continue;
|
|
@@ -6,7 +6,7 @@ const title = 'Jest';
|
|
|
6
6
|
const enablers = ['jest'];
|
|
7
7
|
const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, enablers) || Boolean(manifest.name?.startsWith('jest-presets'));
|
|
8
8
|
const config = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
|
|
9
|
-
const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
|
|
9
|
+
const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', '**/__mocks__/**/*.[jt]s'];
|
|
10
10
|
const resolveDependencies = async (config, options) => {
|
|
11
11
|
const { configFileDir } = options;
|
|
12
12
|
if (config?.preset) {
|
|
@@ -23,7 +23,7 @@ export declare const isConsiderReferencedNS: (node: ts.Identifier) => boolean;
|
|
|
23
23
|
export declare const isObjectEnumerationCallExpressionArgument: (node: ts.Identifier) => boolean;
|
|
24
24
|
export declare const isInForIteration: (node: ts.Node) => boolean;
|
|
25
25
|
export declare const isTopLevel: (node: ts.Node) => boolean;
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const getTypeRef: (node: ts.Identifier) => ts.TypeReferenceNode | undefined;
|
|
27
27
|
export declare const isImportSpecifier: (node: ts.Node) => boolean;
|
|
28
28
|
export declare const isReferencedInExport: (node: ts.Node) => boolean;
|
|
29
29
|
export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
|
|
@@ -150,12 +150,10 @@ export const isObjectEnumerationCallExpressionArgument = (node) => ts.isCallExpr
|
|
|
150
150
|
objectEnumerationMethods.has(String(node.parent.expression.name.escapedText));
|
|
151
151
|
export const isInForIteration = (node) => node.parent && (ts.isForInStatement(node.parent) || ts.isForOfStatement(node.parent));
|
|
152
152
|
export const isTopLevel = (node) => ts.isSourceFile(node.parent) || (node.parent && ts.isSourceFile(node.parent.parent));
|
|
153
|
-
export const
|
|
153
|
+
export const getTypeRef = (node) => {
|
|
154
154
|
if (!node.parent?.parent)
|
|
155
155
|
return;
|
|
156
|
-
|
|
157
|
-
if (typeRef && ts.isQualifiedName(typeRef.typeName))
|
|
158
|
-
return typeRef.typeName;
|
|
156
|
+
return findAncestor(node, _node => ts.isTypeReferenceNode(_node));
|
|
159
157
|
};
|
|
160
158
|
export const isImportSpecifier = (node) => ts.isImportSpecifier(node.parent) ||
|
|
161
159
|
ts.isImportEqualsDeclaration(node.parent) ||
|
|
@@ -6,7 +6,7 @@ import { addNsValue, addValue, createImports } from '../util/dependency-graph.js
|
|
|
6
6
|
import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
7
7
|
import { isInNodeModules } from '../util/path.js';
|
|
8
8
|
import { shouldIgnore } from '../util/tag.js';
|
|
9
|
-
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition,
|
|
9
|
+
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeRef, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isInForIteration, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
|
|
10
10
|
import { findInternalReferences, isType } from './find-internal-references.js';
|
|
11
11
|
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
|
|
12
12
|
import getExportVisitors from './visitors/exports/index.js';
|
|
@@ -265,23 +265,27 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
265
265
|
addNsMemberRefs(imports, id, members);
|
|
266
266
|
}
|
|
267
267
|
else {
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (isConsiderReferencedNS(node)) {
|
|
276
|
-
imports.refs.add(id);
|
|
277
|
-
}
|
|
278
|
-
else if (isObjectEnumerationCallExpressionArgument(node)) {
|
|
279
|
-
imports.refs.add(id);
|
|
268
|
+
const typeRef = getTypeRef(node);
|
|
269
|
+
if (typeRef) {
|
|
270
|
+
if (ts.isQualifiedName(typeRef.typeName)) {
|
|
271
|
+
const typeName = typeRef.typeName;
|
|
272
|
+
const [ns, ...right] = [typeName.left.getText(), typeName.right.getText()].join('.').split('.');
|
|
273
|
+
const members = right.map((_r, index) => right.slice(0, index + 1).join('.'));
|
|
274
|
+
addNsMemberRefs(imports, ns, members);
|
|
280
275
|
}
|
|
281
|
-
else
|
|
276
|
+
else {
|
|
282
277
|
imports.refs.add(id);
|
|
283
278
|
}
|
|
284
279
|
}
|
|
280
|
+
else if (imports.importedNs.has(id) && isConsiderReferencedNS(node)) {
|
|
281
|
+
imports.refs.add(id);
|
|
282
|
+
}
|
|
283
|
+
else if (isObjectEnumerationCallExpressionArgument(node)) {
|
|
284
|
+
imports.refs.add(id);
|
|
285
|
+
}
|
|
286
|
+
else if (isInForIteration(node)) {
|
|
287
|
+
imports.refs.add(id);
|
|
288
|
+
}
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
291
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { DependencyGraph, ImportDetails } from '../types/dependency-graph.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const hasStrictlyEnumReferences: (importsForExport: ImportDetails | undefined, id: string) => boolean;
|
|
3
|
+
export declare const hasStrictlyNsReferences: (graph: DependencyGraph, importsForExport: ImportDetails | undefined, id: string) => [boolean, string?];
|
|
3
4
|
export declare const getType: (hasOnlyNsReference: boolean, isType: boolean) => "exports" | "types" | "nsExports" | "nsTypes";
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { IMPORT_STAR } from '../constants.js';
|
|
2
|
-
export const
|
|
2
|
+
export const hasStrictlyEnumReferences = (importsForExport, id) => {
|
|
3
|
+
if (!importsForExport || !importsForExport.refs.has(id))
|
|
4
|
+
return false;
|
|
5
|
+
for (const ref of importsForExport.refs)
|
|
6
|
+
if (ref.startsWith(`${id}.`))
|
|
7
|
+
return false;
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
export const hasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
3
11
|
if (!importsForExport)
|
|
4
12
|
return [false];
|
|
5
13
|
let namespace;
|
|
@@ -15,9 +23,9 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
15
23
|
for (const filePath of byFilePaths) {
|
|
16
24
|
const file = graph.get(filePath);
|
|
17
25
|
if (file?.imported) {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
26
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
|
|
27
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
28
|
+
return hasStrictlyNsRefs;
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
31
|
}
|
|
@@ -27,9 +35,9 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
27
35
|
for (const filePath of byFilePaths) {
|
|
28
36
|
const file = graph.get(filePath);
|
|
29
37
|
if (file?.imported) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
38
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
|
|
39
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
40
|
+
return hasStrictlyNsRefs;
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
}
|
|
@@ -41,10 +49,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
41
49
|
for (const filePath of byFilePaths) {
|
|
42
50
|
const file = graph.get(filePath);
|
|
43
51
|
if (file?.imported) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
47
|
-
namespace =
|
|
52
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
|
|
53
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
54
|
+
return hasStrictlyNsRefs;
|
|
55
|
+
namespace = hasStrictlyNsRefs[1];
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -54,10 +62,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
54
62
|
for (const filePath of byFilePaths) {
|
|
55
63
|
const file = graph.get(filePath);
|
|
56
64
|
if (file?.imported) {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
60
|
-
namespace =
|
|
65
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, id);
|
|
66
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
67
|
+
return hasStrictlyNsRefs;
|
|
68
|
+
namespace = hasStrictlyNsRefs[1];
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
@@ -69,10 +77,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
69
77
|
for (const filePath of filePaths) {
|
|
70
78
|
const file = graph.get(filePath);
|
|
71
79
|
if (file?.imported) {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
namespace =
|
|
80
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, [alias, ...rest].join('.'));
|
|
81
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
82
|
+
return hasStrictlyNsRefs;
|
|
83
|
+
namespace = hasStrictlyNsRefs[1];
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
@@ -81,10 +89,10 @@ export const getHasStrictlyNsReferences = (graph, importsForExport, id) => {
|
|
|
81
89
|
for (const filePath of filePaths) {
|
|
82
90
|
const file = graph.get(filePath);
|
|
83
91
|
if (file?.imported) {
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
return
|
|
87
|
-
namespace =
|
|
92
|
+
const hasStrictlyNsRefs = hasStrictlyNsReferences(graph, file.imported, `${ns}.${id}`);
|
|
93
|
+
if (hasStrictlyNsRefs[0] === false)
|
|
94
|
+
return hasStrictlyNsRefs;
|
|
95
|
+
namespace = hasStrictlyNsRefs[1];
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.43.
|
|
1
|
+
export declare const version = "5.43.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.43.
|
|
1
|
+
export const version = '5.43.4';
|