knip 5.3.1 → 5.4.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/dist/ConfigurationChief.d.ts +3 -1
- package/dist/ConfigurationChief.js +13 -10
- package/dist/ConfigurationValidator.d.ts +8 -0
- package/dist/ConfigurationValidator.js +2 -0
- package/dist/compilers/index.d.ts +2 -0
- package/dist/index.js +5 -2
- package/dist/types/config.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +5 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPkgGraph } from '@pnpm/workspace.pkgs-graph';
|
|
2
|
-
import type { Configuration, WorkspaceConfiguration } from './types/config.js';
|
|
2
|
+
import type { Configuration, WorkspaceConfiguration, IgnorePatterns } from './types/config.js';
|
|
3
3
|
import type { PackageJson } from './types/package-json.js';
|
|
4
4
|
type ConfigurationManagerOptions = {
|
|
5
5
|
cwd: string;
|
|
@@ -14,6 +14,7 @@ export type Workspace = {
|
|
|
14
14
|
ancestors: string[];
|
|
15
15
|
config: WorkspaceConfiguration;
|
|
16
16
|
manifestPath: string;
|
|
17
|
+
ignoreMembers: IgnorePatterns;
|
|
17
18
|
};
|
|
18
19
|
export declare class ConfigurationChief {
|
|
19
20
|
cwd: string;
|
|
@@ -63,6 +64,7 @@ export declare class ConfigurationChief {
|
|
|
63
64
|
private getIgnoredWorkspacesFor;
|
|
64
65
|
getNegatedWorkspacePatterns(name: string): string[];
|
|
65
66
|
private getConfigKeyForWorkspace;
|
|
67
|
+
getWorkspaceConfig(workspaceName: string): any;
|
|
66
68
|
getIgnores(workspaceName: string): {
|
|
67
69
|
ignoreBinaries: (string | RegExp)[];
|
|
68
70
|
ignoreDependencies: (string | RegExp)[];
|
|
@@ -37,6 +37,7 @@ const defaultConfig = {
|
|
|
37
37
|
ignore: [],
|
|
38
38
|
ignoreBinaries: [],
|
|
39
39
|
ignoreDependencies: [],
|
|
40
|
+
ignoreMembers: [],
|
|
40
41
|
ignoreExportsUsedInFile: false,
|
|
41
42
|
ignoreWorkspaces: [],
|
|
42
43
|
isIncludeEntryExports: false,
|
|
@@ -123,6 +124,7 @@ export class ConfigurationChief {
|
|
|
123
124
|
const ignore = arrayify(rawConfig.ignore ?? defaultConfig.ignore);
|
|
124
125
|
const ignoreBinaries = (rawConfig.ignoreBinaries ?? []).map(toRegexOrString);
|
|
125
126
|
const ignoreDependencies = (rawConfig.ignoreDependencies ?? []).map(toRegexOrString);
|
|
127
|
+
const ignoreMembers = (rawConfig.ignoreMembers ?? []).map(toRegexOrString);
|
|
126
128
|
const ignoreExportsUsedInFile = rawConfig.ignoreExportsUsedInFile ?? false;
|
|
127
129
|
const ignoreWorkspaces = rawConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
|
|
128
130
|
const isIncludeEntryExports = rawConfig.includeEntryExports ?? this.isIncludeEntryExports;
|
|
@@ -141,6 +143,7 @@ export class ConfigurationChief {
|
|
|
141
143
|
ignore,
|
|
142
144
|
ignoreBinaries,
|
|
143
145
|
ignoreDependencies,
|
|
146
|
+
ignoreMembers,
|
|
144
147
|
ignoreExportsUsedInFile,
|
|
145
148
|
ignoreWorkspaces,
|
|
146
149
|
isIncludeEntryExports,
|
|
@@ -271,6 +274,8 @@ export class ConfigurationChief {
|
|
|
271
274
|
.map((name) => {
|
|
272
275
|
const dir = join(this.cwd, name);
|
|
273
276
|
const pkgName = this.availableWorkspaceManifests.find(p => p.dir === dir)?.manifest.name ?? `NOT_FOUND_${name}`;
|
|
277
|
+
const workspaceConfig = this.getWorkspaceConfig(name);
|
|
278
|
+
const ignoreMembers = arrayify(workspaceConfig.ignoreMembers).map(toRegexOrString);
|
|
274
279
|
return {
|
|
275
280
|
name,
|
|
276
281
|
pkgName,
|
|
@@ -278,6 +283,7 @@ export class ConfigurationChief {
|
|
|
278
283
|
config: this.getConfigForWorkspace(name),
|
|
279
284
|
ancestors: this.availableWorkspaceNames.reduce(getAncestors(name), []),
|
|
280
285
|
manifestPath: join(dir, 'package.json'),
|
|
286
|
+
ignoreMembers,
|
|
281
287
|
};
|
|
282
288
|
});
|
|
283
289
|
}
|
|
@@ -311,27 +317,24 @@ export class ConfigurationChief {
|
|
|
311
317
|
.reverse()
|
|
312
318
|
.find(pattern => micromatch.isMatch(workspaceName, pattern));
|
|
313
319
|
}
|
|
314
|
-
|
|
320
|
+
getWorkspaceConfig(workspaceName) {
|
|
315
321
|
const key = this.getConfigKeyForWorkspace(workspaceName);
|
|
316
322
|
const workspaces = this.rawConfig?.workspaces ?? {};
|
|
317
|
-
|
|
323
|
+
return ((key
|
|
318
324
|
? key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces)
|
|
319
325
|
? this.rawConfig
|
|
320
326
|
: workspaces[key]
|
|
321
|
-
: {}) ?? {};
|
|
327
|
+
: {}) ?? {});
|
|
328
|
+
}
|
|
329
|
+
getIgnores(workspaceName) {
|
|
330
|
+
const workspaceConfig = this.getWorkspaceConfig(workspaceName);
|
|
322
331
|
const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries).map(toRegexOrString);
|
|
323
332
|
const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies).map(toRegexOrString);
|
|
324
333
|
return { ignoreBinaries, ignoreDependencies };
|
|
325
334
|
}
|
|
326
335
|
getConfigForWorkspace(workspaceName, extensions) {
|
|
327
336
|
const baseConfig = getDefaultWorkspaceConfig(extensions);
|
|
328
|
-
const
|
|
329
|
-
const workspaces = this.rawConfig?.workspaces ?? {};
|
|
330
|
-
const workspaceConfig = (key
|
|
331
|
-
? key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces)
|
|
332
|
-
? this.rawConfig
|
|
333
|
-
: workspaces[key]
|
|
334
|
-
: {}) ?? {};
|
|
337
|
+
const workspaceConfig = this.getWorkspaceConfig(workspaceName);
|
|
335
338
|
const entry = workspaceConfig.entry ? arrayify(workspaceConfig.entry) : baseConfig.entry;
|
|
336
339
|
const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : baseConfig.project;
|
|
337
340
|
const paths = workspaceConfig.paths ?? {};
|
|
@@ -21,6 +21,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
21
21
|
ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
22
22
|
ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
23
23
|
ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
24
|
+
ignoreMembers: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
24
25
|
ignoreExportsUsedInFile: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodRecord<z.ZodUnion<[z.ZodLiteral<"class">, z.ZodLiteral<"enum">, z.ZodLiteral<"function">, z.ZodLiteral<"interface">, z.ZodLiteral<"member">, z.ZodLiteral<"type">]>, z.ZodBoolean>]>>;
|
|
25
26
|
ignoreWorkspaces: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
26
27
|
includeEntryExports: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -35,6 +36,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
35
36
|
ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
36
37
|
ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
37
38
|
ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
39
|
+
ignoreMembers: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>, "many">>;
|
|
38
40
|
includeEntryExports: z.ZodOptional<z.ZodBoolean>;
|
|
39
41
|
astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
40
42
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -758,6 +760,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
758
760
|
ignore?: string | string[] | undefined;
|
|
759
761
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
760
762
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
763
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
761
764
|
includeEntryExports?: boolean | undefined;
|
|
762
765
|
astro?: string | boolean | string[] | {
|
|
763
766
|
config?: string | string[] | undefined;
|
|
@@ -1041,6 +1044,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1041
1044
|
ignore?: string | string[] | undefined;
|
|
1042
1045
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
1043
1046
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
1047
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
1044
1048
|
includeEntryExports?: boolean | undefined;
|
|
1045
1049
|
astro?: string | boolean | string[] | {
|
|
1046
1050
|
config?: string | string[] | undefined;
|
|
@@ -2042,6 +2046,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2042
2046
|
ignore?: string | string[] | undefined;
|
|
2043
2047
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
2044
2048
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
2049
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
2045
2050
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
2046
2051
|
ignoreWorkspaces?: string[] | undefined;
|
|
2047
2052
|
includeEntryExports?: boolean | undefined;
|
|
@@ -2056,6 +2061,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2056
2061
|
ignore?: string | string[] | undefined;
|
|
2057
2062
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
2058
2063
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
2064
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
2059
2065
|
includeEntryExports?: boolean | undefined;
|
|
2060
2066
|
astro?: string | boolean | string[] | {
|
|
2061
2067
|
config?: string | string[] | undefined;
|
|
@@ -2617,6 +2623,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2617
2623
|
ignore?: string | string[] | undefined;
|
|
2618
2624
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
2619
2625
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
2626
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
2620
2627
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
2621
2628
|
ignoreWorkspaces?: string[] | undefined;
|
|
2622
2629
|
includeEntryExports?: boolean | undefined;
|
|
@@ -2631,6 +2638,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2631
2638
|
ignore?: string | string[] | undefined;
|
|
2632
2639
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
2633
2640
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
2641
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
2634
2642
|
includeEntryExports?: boolean | undefined;
|
|
2635
2643
|
astro?: string | boolean | string[] | {
|
|
2636
2644
|
config?: string | string[] | undefined;
|
|
@@ -41,6 +41,7 @@ const rootConfigurationSchema = z.object({
|
|
|
41
41
|
ignore: globSchema.optional(),
|
|
42
42
|
ignoreBinaries: stringOrRegexSchema.optional(),
|
|
43
43
|
ignoreDependencies: stringOrRegexSchema.optional(),
|
|
44
|
+
ignoreMembers: stringOrRegexSchema.optional(),
|
|
44
45
|
ignoreExportsUsedInFile: ignoreExportsUsedInFileSchema.optional(),
|
|
45
46
|
ignoreWorkspaces: z.array(z.string()).optional(),
|
|
46
47
|
includeEntryExports: z.boolean().optional(),
|
|
@@ -125,6 +126,7 @@ const baseWorkspaceConfigurationSchema = z.object({
|
|
|
125
126
|
ignore: globSchema.optional(),
|
|
126
127
|
ignoreBinaries: stringOrRegexSchema.optional(),
|
|
127
128
|
ignoreDependencies: stringOrRegexSchema.optional(),
|
|
129
|
+
ignoreMembers: stringOrRegexSchema.optional(),
|
|
128
130
|
includeEntryExports: z.boolean().optional(),
|
|
129
131
|
});
|
|
130
132
|
const workspaceConfigurationSchema = baseWorkspaceConfigurationSchema.merge(pluginsSchema.partial());
|
|
@@ -12,6 +12,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
12
12
|
ignore?: string | string[] | undefined;
|
|
13
13
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
14
14
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
15
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
15
16
|
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
16
17
|
ignoreWorkspaces?: string[] | undefined;
|
|
17
18
|
includeEntryExports?: boolean | undefined;
|
|
@@ -24,6 +25,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
24
25
|
ignore?: string | string[] | undefined;
|
|
25
26
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
26
27
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
28
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
27
29
|
includeEntryExports?: boolean | undefined;
|
|
28
30
|
astro?: string | boolean | string[] | {
|
|
29
31
|
config?: string | string[] | undefined;
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { getGitIgnoredFn } from './util/globby.js';
|
|
|
14
14
|
import { getHandler } from './util/handleReferencedDependency.js';
|
|
15
15
|
import { getEntryPathFromManifest, getPackageNameFromModuleSpecifier } from './util/modules.js';
|
|
16
16
|
import { dirname, join } from './util/path.js';
|
|
17
|
+
import { hasMatch } from './util/regex.js';
|
|
17
18
|
import { shouldIgnore } from './util/tag.js';
|
|
18
19
|
import { loadTSConfig } from './util/tsconfig-loader.js';
|
|
19
20
|
import { getType, getHasStrictlyNsReferences } from './util/type.js';
|
|
@@ -273,7 +274,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
273
274
|
});
|
|
274
275
|
principal.getUnreferencedFiles().forEach(filePath => unreferencedFiles.add(filePath));
|
|
275
276
|
principal.entryPaths.forEach(filePath => entryPaths.add(filePath));
|
|
276
|
-
if (
|
|
277
|
+
if (isSkipLibs)
|
|
277
278
|
factory.deletePrincipal(principal);
|
|
278
279
|
}
|
|
279
280
|
const isIdentifierReferenced = (filePath, id, importsForExport, depth = 0) => {
|
|
@@ -397,6 +398,8 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
397
398
|
if (isIdentifierReferenced(filePath, identifier, importsForExport)) {
|
|
398
399
|
if (exportedItem.type === 'enum') {
|
|
399
400
|
exportedItem.members?.forEach(member => {
|
|
401
|
+
if (hasMatch(workspace.ignoreMembers, member.identifier))
|
|
402
|
+
return;
|
|
400
403
|
if (shouldIgnore(member.jsDocTags, tags))
|
|
401
404
|
return;
|
|
402
405
|
if (member.refs === 0) {
|
|
@@ -472,7 +475,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
472
475
|
const workspace = chief.findWorkspaceByFilePath(filePath);
|
|
473
476
|
const principal = workspace && factory.getPrincipalByPackageName(workspace.pkgName);
|
|
474
477
|
if (principal) {
|
|
475
|
-
const members = exportedItem.members.filter(member => !shouldIgnore(member.jsDocTags, tags));
|
|
478
|
+
const members = exportedItem.members.filter(member => !hasMatch(workspace.ignoreMembers, member.identifier) && !shouldIgnore(member.jsDocTags, tags));
|
|
476
479
|
principal.findUnusedMembers(filePath, members).forEach(member => {
|
|
477
480
|
collector.addIssue({
|
|
478
481
|
type: 'classMembers',
|
package/dist/types/config.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface Configuration {
|
|
|
34
34
|
ignoreBinaries: IgnorePatterns;
|
|
35
35
|
ignoreDependencies: IgnorePatterns;
|
|
36
36
|
ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
|
|
37
|
+
ignoreMembers: IgnorePatterns;
|
|
37
38
|
ignoreWorkspaces: string[];
|
|
38
39
|
isIncludeEntryExports: boolean;
|
|
39
40
|
syncCompilers: SyncCompilers;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.4.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.4.0';
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"examples": ["husky", "lint-staged"],
|
|
32
32
|
"$ref": "#/definitions/list"
|
|
33
33
|
},
|
|
34
|
+
"ignoreMembers": {
|
|
35
|
+
"title": "Class members to ignore (regex allowed)",
|
|
36
|
+
"examples": ["render", "on.*"],
|
|
37
|
+
"$ref": "#/definitions/list"
|
|
38
|
+
},
|
|
34
39
|
"ignoreWorkspaces": {
|
|
35
40
|
"title": "Workspaces to ignore",
|
|
36
41
|
"examples": ["packages/ignore-me"],
|