knip 5.30.6 → 5.32.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.
Files changed (50) hide show
  1. package/dist/ConfigurationChief.d.ts +1 -0
  2. package/dist/ConfigurationValidator.d.ts +56 -0
  3. package/dist/ConfigurationValidator.js +1 -0
  4. package/dist/IssueFixer.d.ts +4 -4
  5. package/dist/IssueFixer.js +9 -12
  6. package/dist/WorkspaceWorker.d.ts +2 -2
  7. package/dist/binaries/bash-parser.js +3 -4
  8. package/dist/compilers/index.d.ts +10 -0
  9. package/dist/constants.d.ts +5 -0
  10. package/dist/constants.js +6 -1
  11. package/dist/index.js +10 -4
  12. package/dist/plugins/index.d.ts +1 -0
  13. package/dist/plugins/index.js +1 -0
  14. package/dist/plugins/nyc/index.js +4 -2
  15. package/dist/plugins/nyc/types.d.ts +1 -0
  16. package/dist/plugins/stylelint/index.js +4 -3
  17. package/dist/plugins/stylelint/types.d.ts +1 -0
  18. package/dist/plugins/travis/index.d.ts +9 -0
  19. package/dist/plugins/travis/index.js +22 -0
  20. package/dist/reporters/symbols.js +2 -2
  21. package/dist/types/config.d.ts +2 -1
  22. package/dist/types/exports.d.ts +1 -1
  23. package/dist/typescript/SourceFile.d.ts +10 -1
  24. package/dist/typescript/ast-helpers.d.ts +1 -0
  25. package/dist/typescript/ast-helpers.js +9 -1
  26. package/dist/typescript/find-internal-references.d.ts +1 -0
  27. package/dist/typescript/find-internal-references.js +3 -1
  28. package/dist/typescript/get-imports-and-exports.d.ts +2 -1
  29. package/dist/typescript/get-imports-and-exports.js +68 -63
  30. package/dist/typescript/visitors/dynamic-imports/index.js +2 -2
  31. package/dist/typescript/visitors/exports/exportAssignment.js +2 -1
  32. package/dist/typescript/visitors/exports/exportDeclaration.js +6 -2
  33. package/dist/typescript/visitors/exports/exportKeyword.js +9 -7
  34. package/dist/typescript/visitors/exports/exportsAccessExpression.js +2 -1
  35. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +4 -3
  36. package/dist/typescript/visitors/helpers.js +2 -1
  37. package/dist/util/fs.d.ts +0 -1
  38. package/dist/util/fs.js +2 -17
  39. package/dist/util/glob-core.js +1 -1
  40. package/dist/util/jiti.d.ts +1 -2
  41. package/dist/util/jiti.js +3 -8
  42. package/dist/util/loader.js +2 -12
  43. package/dist/util/remove-export.d.ts +8 -0
  44. package/dist/util/remove-export.js +68 -0
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.js +1 -1
  47. package/package.json +3 -3
  48. package/schema.json +4 -0
  49. /package/dist/typescript/visitors/dynamic-imports/{propertyAccessCall.d.ts → resolveCall.d.ts} +0 -0
  50. /package/dist/typescript/visitors/dynamic-imports/{propertyAccessCall.js → resolveCall.js} +0 -0
@@ -123,6 +123,7 @@ export declare class ConfigurationChief {
123
123
  svelte?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
124
124
  syncpack?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
125
125
  tailwind?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
126
+ travis?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
126
127
  tsup?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
127
128
  typedoc?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
128
129
  typescript?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -808,6 +808,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
808
808
  entry?: string | string[] | undefined;
809
809
  project?: string | string[] | undefined;
810
810
  }>]>>;
811
+ travis: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
812
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
813
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
814
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
815
+ }, "strip", z.ZodTypeAny, {
816
+ config?: string | string[] | undefined;
817
+ entry?: string | string[] | undefined;
818
+ project?: string | string[] | undefined;
819
+ }, {
820
+ config?: string | string[] | undefined;
821
+ entry?: string | string[] | undefined;
822
+ project?: string | string[] | undefined;
823
+ }>]>>;
811
824
  tsup: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
812
825
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
813
826
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1320,6 +1333,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
1320
1333
  entry?: string | string[] | undefined;
1321
1334
  project?: string | string[] | undefined;
1322
1335
  } | undefined;
1336
+ travis?: string | boolean | string[] | {
1337
+ config?: string | string[] | undefined;
1338
+ entry?: string | string[] | undefined;
1339
+ project?: string | string[] | undefined;
1340
+ } | undefined;
1323
1341
  tsup?: string | boolean | string[] | {
1324
1342
  config?: string | string[] | undefined;
1325
1343
  entry?: string | string[] | undefined;
@@ -1704,6 +1722,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
1704
1722
  entry?: string | string[] | undefined;
1705
1723
  project?: string | string[] | undefined;
1706
1724
  } | undefined;
1725
+ travis?: string | boolean | string[] | {
1726
+ config?: string | string[] | undefined;
1727
+ entry?: string | string[] | undefined;
1728
+ project?: string | string[] | undefined;
1729
+ } | undefined;
1707
1730
  tsup?: string | boolean | string[] | {
1708
1731
  config?: string | string[] | undefined;
1709
1732
  entry?: string | string[] | undefined;
@@ -2553,6 +2576,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
2553
2576
  entry?: string | string[] | undefined;
2554
2577
  project?: string | string[] | undefined;
2555
2578
  }>]>>;
2579
+ travis: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2580
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2581
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2582
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2583
+ }, "strip", z.ZodTypeAny, {
2584
+ config?: string | string[] | undefined;
2585
+ entry?: string | string[] | undefined;
2586
+ project?: string | string[] | undefined;
2587
+ }, {
2588
+ config?: string | string[] | undefined;
2589
+ entry?: string | string[] | undefined;
2590
+ project?: string | string[] | undefined;
2591
+ }>]>>;
2556
2592
  tsup: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2557
2593
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2558
2594
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -3073,6 +3109,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3073
3109
  entry?: string | string[] | undefined;
3074
3110
  project?: string | string[] | undefined;
3075
3111
  } | undefined;
3112
+ travis?: string | boolean | string[] | {
3113
+ config?: string | string[] | undefined;
3114
+ entry?: string | string[] | undefined;
3115
+ project?: string | string[] | undefined;
3116
+ } | undefined;
3076
3117
  tsup?: string | boolean | string[] | {
3077
3118
  config?: string | string[] | undefined;
3078
3119
  entry?: string | string[] | undefined;
@@ -3457,6 +3498,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3457
3498
  entry?: string | string[] | undefined;
3458
3499
  project?: string | string[] | undefined;
3459
3500
  } | undefined;
3501
+ travis?: string | boolean | string[] | {
3502
+ config?: string | string[] | undefined;
3503
+ entry?: string | string[] | undefined;
3504
+ project?: string | string[] | undefined;
3505
+ } | undefined;
3460
3506
  tsup?: string | boolean | string[] | {
3461
3507
  config?: string | string[] | undefined;
3462
3508
  entry?: string | string[] | undefined;
@@ -3850,6 +3896,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3850
3896
  entry?: string | string[] | undefined;
3851
3897
  project?: string | string[] | undefined;
3852
3898
  } | undefined;
3899
+ travis?: string | boolean | string[] | {
3900
+ config?: string | string[] | undefined;
3901
+ entry?: string | string[] | undefined;
3902
+ project?: string | string[] | undefined;
3903
+ } | undefined;
3853
3904
  tsup?: string | boolean | string[] | {
3854
3905
  config?: string | string[] | undefined;
3855
3906
  entry?: string | string[] | undefined;
@@ -4234,6 +4285,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
4234
4285
  entry?: string | string[] | undefined;
4235
4286
  project?: string | string[] | undefined;
4236
4287
  } | undefined;
4288
+ travis?: string | boolean | string[] | {
4289
+ config?: string | string[] | undefined;
4290
+ entry?: string | string[] | undefined;
4291
+ project?: string | string[] | undefined;
4292
+ } | undefined;
4237
4293
  tsup?: string | boolean | string[] | {
4238
4294
  config?: string | string[] | undefined;
4239
4295
  entry?: string | string[] | undefined;
@@ -123,6 +123,7 @@ const pluginsSchema = z.object({
123
123
  svelte: pluginSchema,
124
124
  syncpack: pluginSchema,
125
125
  tailwind: pluginSchema,
126
+ travis: pluginSchema,
126
127
  tsup: pluginSchema,
127
128
  typedoc: pluginSchema,
128
129
  typescript: pluginSchema,
@@ -1,4 +1,4 @@
1
- import type { Fixes } from './types/exports.js';
1
+ import type { Fix, Fixes } from './types/exports.js';
2
2
  import type { Issues } from './types/issues.js';
3
3
  interface Fixer {
4
4
  isEnabled: boolean;
@@ -13,15 +13,15 @@ export declare class IssueFixer {
13
13
  isFixDependencies: boolean;
14
14
  isFixUnusedTypes: boolean;
15
15
  isFixUnusedExports: boolean;
16
- unusedTypeNodes: Map<string, Set<[number, number]>>;
17
- unusedExportNodes: Map<string, Set<[number, number]>>;
16
+ unusedTypeNodes: Map<string, Set<Fix>>;
17
+ unusedExportNodes: Map<string, Set<Fix>>;
18
18
  constructor({ isEnabled, cwd, fixTypes, isRemoveFiles }: Fixer);
19
19
  addUnusedTypeNode(filePath: string, fixes: Fixes | undefined): void;
20
20
  addUnusedExportNode(filePath: string, fixes: Fixes | undefined): void;
21
21
  fixIssues(issues: Issues): Promise<void>;
22
22
  private markExportFixed;
23
23
  private removeUnusedFiles;
24
- private removeUnusedExportKeywords;
24
+ private removeUnusedExports;
25
25
  private removeUnusedDependencies;
26
26
  }
27
27
  export {};
@@ -1,6 +1,7 @@
1
1
  import { readFile, rm, writeFile } from 'node:fs/promises';
2
2
  import { load, save } from './util/package-json.js';
3
3
  import { join, relative } from './util/path.js';
4
+ import { removeExport } from './util/remove-export.js';
4
5
  export class IssueFixer {
5
6
  isEnabled = false;
6
7
  cwd = process.cwd();
@@ -38,13 +39,13 @@ export class IssueFixer {
38
39
  }
39
40
  async fixIssues(issues) {
40
41
  await this.removeUnusedFiles(issues);
41
- await this.removeUnusedExportKeywords(issues);
42
+ await this.removeUnusedExports(issues);
42
43
  await this.removeUnusedDependencies(issues);
43
44
  }
44
45
  markExportFixed(issues, filePath) {
45
46
  const relPath = relative(filePath);
46
47
  const types = [
47
- ...(this.isFixUnusedTypes ? ['types', 'nsTypes'] : []),
48
+ ...(this.isFixUnusedTypes ? ['types', 'nsTypes', 'classMembers', 'enumMembers'] : []),
48
49
  ...(this.isFixUnusedExports ? ['exports', 'nsExports'] : []),
49
50
  ];
50
51
  for (const type of types) {
@@ -61,19 +62,15 @@ export class IssueFixer {
61
62
  issue.isFixed = true;
62
63
  }
63
64
  }
64
- async removeUnusedExportKeywords(issues) {
65
+ async removeUnusedExports(issues) {
65
66
  const filePaths = new Set([...this.unusedTypeNodes.keys(), ...this.unusedExportNodes.keys()]);
66
67
  for (const filePath of filePaths) {
67
- const exportPositions = [
68
- ...(this.isFixUnusedTypes ? (this.unusedTypeNodes.get(filePath) ?? []) : []),
69
- ...(this.isFixUnusedExports ? (this.unusedExportNodes.get(filePath) ?? []) : []),
70
- ].sort((a, b) => b[0] - a[0]);
68
+ const types = (this.isFixUnusedTypes && this.unusedTypeNodes.get(filePath)) || [];
69
+ const exports = (this.isFixUnusedExports && this.unusedExportNodes.get(filePath)) || [];
70
+ const exportPositions = [...types, ...exports].filter(fix => fix !== undefined).sort((a, b) => b[0] - a[0]);
71
71
  if (exportPositions.length > 0) {
72
- const sourceFileText = exportPositions.reduce((text, [start, end]) => text.substring(0, start) + text.substring(end), await readFile(filePath, 'utf-8'));
73
- const withoutEmptyReExports = sourceFileText
74
- .replaceAll(/export \{[ ,]+\} from ('|")[^'"]+('|");?\r?\n?/g, '')
75
- .replaceAll(/export \{[ ,]+\};?\r?\n?/g, '');
76
- await writeFile(filePath, withoutEmptyReExports);
72
+ const sourceFileText = exportPositions.reduce((text, [start, end, flags]) => removeExport({ text, start, end, flags }), await readFile(filePath, 'utf-8'));
73
+ await writeFile(filePath, sourceFileText);
77
74
  this.markExportFixed(issues, filePath);
78
75
  }
79
76
  }
@@ -34,7 +34,7 @@ export declare class WorkspaceWorker {
34
34
  isStrict: boolean;
35
35
  rootIgnore: Configuration['ignore'];
36
36
  negatedWorkspacePatterns: string[];
37
- enabledPluginsMap: Record<"astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo", boolean>;
37
+ enabledPluginsMap: Record<"astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo", boolean>;
38
38
  enabledPlugins: PluginName[];
39
39
  enabledPluginsInAncestors: string[];
40
40
  cache: CacheConsultant<CacheItem>;
@@ -55,7 +55,7 @@ export declare class WorkspaceWorker {
55
55
  entryFilePatterns: Set<string>;
56
56
  productionEntryFilePatterns: Set<string>;
57
57
  referencedDependencies: ReferencedDependencies;
58
- enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo")[];
58
+ enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo")[];
59
59
  }>;
60
60
  onDispose(): void;
61
61
  }
@@ -15,7 +15,8 @@ export const getBinariesFromScript = (script, options) => {
15
15
  const getBinariesFromNodes = (nodes) => nodes.flatMap(node => {
16
16
  switch (node.type) {
17
17
  case 'Command': {
18
- const binary = node.name?.text ? trimBinary(node.name.text) : node.name?.text;
18
+ const text = node.name?.text;
19
+ const binary = text ? trimBinary(text) : text;
19
20
  const commandExpansions = node.prefix
20
21
  ?.filter(isExpansion)
21
22
  .map(prefix => prefix.expansion)
@@ -27,8 +28,6 @@ export const getBinariesFromScript = (script, options) => {
27
28
  return [];
28
29
  if (binary.startsWith('-') || binary.startsWith('"') || binary.startsWith('..'))
29
30
  return [];
30
- if (['deno'].includes(binary))
31
- return [];
32
31
  const args = node.suffix?.map(arg => arg.text) ?? [];
33
32
  if (['!', 'test'].includes(binary))
34
33
  return fromArgs(args);
@@ -47,7 +46,7 @@ export const getBinariesFromScript = (script, options) => {
47
46
  const command = script.replace(new RegExp(`.*${node.name?.text ?? binary}(\\s--\\s)?`), '');
48
47
  return [toBinary(binary), ...getBinariesFromScript(command, options)];
49
48
  }
50
- if (options.knownGlobalsOnly)
49
+ if (options.knownGlobalsOnly && !text?.startsWith('.'))
51
50
  return [];
52
51
  return [...FallbackResolver.resolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
53
52
  }
@@ -313,6 +313,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
313
313
  entry?: string | string[] | undefined;
314
314
  project?: string | string[] | undefined;
315
315
  } | undefined;
316
+ travis?: string | boolean | string[] | {
317
+ config?: string | string[] | undefined;
318
+ entry?: string | string[] | undefined;
319
+ project?: string | string[] | undefined;
320
+ } | undefined;
316
321
  tsup?: string | boolean | string[] | {
317
322
  config?: string | string[] | undefined;
318
323
  entry?: string | string[] | undefined;
@@ -697,6 +702,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
697
702
  entry?: string | string[] | undefined;
698
703
  project?: string | string[] | undefined;
699
704
  } | undefined;
705
+ travis?: string | boolean | string[] | {
706
+ config?: string | string[] | undefined;
707
+ entry?: string | string[] | undefined;
708
+ project?: string | string[] | undefined;
709
+ } | undefined;
700
710
  tsup?: string | boolean | string[] | {
701
711
  config?: string | string[] | undefined;
702
712
  entry?: string | string[] | undefined;
@@ -17,3 +17,8 @@ export declare const FOREIGN_FILE_EXTENSIONS: Set<string>;
17
17
  export declare const IGNORE_DEFINITELY_TYPED: Set<string>;
18
18
  export declare const ISSUE_TYPES: IssueType[];
19
19
  export declare const ISSUE_TYPE_TITLE: Record<IssueType, string>;
20
+ export declare const FIX_FLAGS: {
21
+ readonly NONE: 0;
22
+ readonly OBJECT_BINDING: number;
23
+ readonly EMPTY_DECLARATION: number;
24
+ };
package/dist/constants.js CHANGED
@@ -118,7 +118,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
118
118
  'yes',
119
119
  ]);
120
120
  export const IGNORED_DEPENDENCIES = new Set(['knip', 'typescript']);
121
- export const IGNORED_RUNTIME_DEPENDENCIES = new Set(['bun']);
121
+ export const IGNORED_RUNTIME_DEPENDENCIES = new Set(['bun', 'deno']);
122
122
  export const FOREIGN_FILE_EXTENSIONS = new Set([
123
123
  '.avif',
124
124
  '.css',
@@ -180,3 +180,8 @@ export const ISSUE_TYPE_TITLE = {
180
180
  classMembers: 'Unused exported class members',
181
181
  duplicates: 'Duplicate exports',
182
182
  };
183
+ export const FIX_FLAGS = {
184
+ NONE: 0,
185
+ OBJECT_BINDING: 1 << 0,
186
+ EMPTY_DECLARATION: 1 << 1,
187
+ };
package/dist/index.js CHANGED
@@ -207,7 +207,7 @@ export const main = async (unresolvedConfiguration) => {
207
207
  skipTypeOnly: isStrict,
208
208
  isFixExports: fixer.isEnabled && fixer.isFixUnusedExports,
209
209
  isFixTypes: fixer.isEnabled && fixer.isFixUnusedTypes,
210
- ignoreExportsUsedInFile: Boolean(chief.config.ignoreExportsUsedInFile),
210
+ ignoreExportsUsedInFile: chief.config.ignoreExportsUsedInFile,
211
211
  isReportClassMembers,
212
212
  tags,
213
213
  }, isGitIgnored, isPackageNameInternalWorkspace, getPrincipalByFilePath);
@@ -290,7 +290,7 @@ export const main = async (unresolvedConfiguration) => {
290
290
  }
291
291
  const importsForExport = file.imported;
292
292
  for (const [identifier, exportedItem] of exportItems.entries()) {
293
- if (exportedItem.isReExport)
293
+ if (!isFix && exportedItem.isReExport)
294
294
  continue;
295
295
  if (shouldIgnore(exportedItem.jsDocTags))
296
296
  continue;
@@ -319,6 +319,8 @@ export const main = async (unresolvedConfiguration) => {
319
319
  printTrace(traceNode, filePath, identifier);
320
320
  if (isReferenced) {
321
321
  if (report.enumMembers && exportedItem.type === 'enum') {
322
+ if (importsForExport.refs.has(identifier))
323
+ continue;
322
324
  for (const member of exportedItem.members) {
323
325
  if (findMatch(workspace.ignoreMembers, member.identifier))
324
326
  continue;
@@ -331,7 +333,7 @@ export const main = async (unresolvedConfiguration) => {
331
333
  if (!isReferenced) {
332
334
  if (isIgnored)
333
335
  continue;
334
- collector.addIssue({
336
+ const isIssueAdded = collector.addIssue({
335
337
  type: 'enumMembers',
336
338
  filePath,
337
339
  workspace: workspace.name,
@@ -341,6 +343,8 @@ export const main = async (unresolvedConfiguration) => {
341
343
  line: member.line,
342
344
  col: member.col,
343
345
  });
346
+ if (isFix && isIssueAdded && member.fix)
347
+ fixer.addUnusedTypeNode(filePath, [member.fix]);
344
348
  }
345
349
  else if (isIgnored) {
346
350
  for (const tagName of exportedItem.jsDocTags) {
@@ -364,7 +368,7 @@ export const main = async (unresolvedConfiguration) => {
364
368
  }
365
369
  continue;
366
370
  }
367
- collector.addIssue({
371
+ const isIssueAdded = collector.addIssue({
368
372
  type: 'classMembers',
369
373
  filePath,
370
374
  workspace: workspace.name,
@@ -374,6 +378,8 @@ export const main = async (unresolvedConfiguration) => {
374
378
  line: member.line,
375
379
  col: member.col,
376
380
  });
381
+ if (isFix && isIssueAdded && member.fix)
382
+ fixer.addUnusedTypeNode(filePath, [member.fix]);
377
383
  }
378
384
  }
379
385
  continue;
@@ -58,6 +58,7 @@ export { default as stylelint } from './stylelint/index.js';
58
58
  export { default as svelte } from './svelte/index.js';
59
59
  export { default as syncpack } from './syncpack/index.js';
60
60
  export { default as tailwind } from './tailwind/index.js';
61
+ export { default as travis } from './travis/index.js';
61
62
  export { default as tsup } from './tsup/index.js';
62
63
  export { default as typedoc } from './typedoc/index.js';
63
64
  export { default as typescript } from './typescript/index.js';
@@ -58,6 +58,7 @@ export { default as stylelint } from './stylelint/index.js';
58
58
  export { default as svelte } from './svelte/index.js';
59
59
  export { default as syncpack } from './syncpack/index.js';
60
60
  export { default as tailwind } from './tailwind/index.js';
61
+ export { default as travis } from './travis/index.js';
61
62
  export { default as tsup } from './tsup/index.js';
62
63
  export { default as typedoc } from './typedoc/index.js';
63
64
  export { default as typescript } from './typescript/index.js';
@@ -2,9 +2,11 @@ import { hasDependency } from '#p/util/plugin.js';
2
2
  const title = 'nyc';
3
3
  const enablers = ['nyc'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['.nycrc', '.nycrc.json', '.nycrc.{yml,yaml}', 'nyc.config.js'];
5
+ const config = ['.nycrc', '.nycrc.json', '.nycrc.{yml,yaml}', 'nyc.config.js', 'package.json'];
6
6
  const resolveConfig = config => {
7
- return config?.extends ? [config.extends].flat() : [];
7
+ const extend = config?.extends ? [config?.extends].flat() : [];
8
+ const requires = config?.require ? [config?.require].flat() : [];
9
+ return [...extend, ...requires].flat();
8
10
  };
9
11
  export default {
10
12
  title,
@@ -1,3 +1,4 @@
1
1
  export type NycConfig = {
2
2
  extends?: string;
3
+ require?: string[];
3
4
  };
@@ -5,10 +5,11 @@ const enablers = ['stylelint'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
6
  const config = ['package.json', ...toCosmiconfig('stylelint')];
7
7
  const resolve = (config) => {
8
- const extend = config.extends ? [config.extends].flat().filter(id => !isInternal(id)) : [];
9
- const plugins = config.plugins ? [config.plugins].flat().filter(id => !isInternal(id)) : [];
8
+ const extend = config.extends ? [config.extends].flat() : [];
9
+ const plugins = config.plugins ? [config.plugins].flat() : [];
10
+ const customSyntax = config.customSyntax ? [config.customSyntax] : [];
10
11
  const overrideConfigs = 'overrides' in config ? config.overrides.flatMap(resolve) : [];
11
- return [...extend, ...plugins, ...overrideConfigs];
12
+ return [...extend, ...plugins, ...overrideConfigs, ...customSyntax].filter(id => !isInternal(id));
12
13
  };
13
14
  const resolveConfig = config => resolve(config);
14
15
  export default {
@@ -1,4 +1,5 @@
1
1
  export type BaseStyleLintConfig = {
2
+ customSyntax?: string;
2
3
  extends?: string | string[];
3
4
  plugins?: string[];
4
5
  };
@@ -0,0 +1,9 @@
1
+ import type { IsPluginEnabled, ResolveConfig } from '#p/types/plugins.js';
2
+ declare const _default: {
3
+ title: string;
4
+ enablers: string;
5
+ isEnabled: IsPluginEnabled;
6
+ config: string[];
7
+ resolveConfig: ResolveConfig;
8
+ };
9
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import { _glob } from '#p/util/glob.js';
2
+ import { getDependenciesFromScripts } from '../../util/plugin.js';
3
+ const title = 'Travis CI';
4
+ const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';
5
+ const isEnabled = async ({ cwd }) => Boolean(await _glob({ cwd, patterns: ['.travis.yml'] }));
6
+ const config = ['.travis.yml'];
7
+ const resolveConfig = async (config, options) => {
8
+ if (!config)
9
+ return [];
10
+ const beforeDeploy = [config.before_deploy ?? []].flat();
11
+ const beforeInstall = [config.before_install ?? []].flat();
12
+ const beforeScript = [config.before_script ?? []].flat();
13
+ const scripts = [...beforeDeploy, ...beforeInstall, ...beforeScript];
14
+ return getDependenciesFromScripts(scripts, { ...options, knownGlobalsOnly: true });
15
+ };
16
+ export default {
17
+ title,
18
+ enablers,
19
+ isEnabled,
20
+ config,
21
+ resolveConfig,
22
+ };
@@ -15,7 +15,7 @@ const logIssueRecord = (issues) => {
15
15
  const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
16
16
  const cell = `${relative(issue.filePath)}${pos}`;
17
17
  table.cell('filePath', print(cell));
18
- issue.isFixed && table.cell('fixed', print('(fixed)'));
18
+ issue.isFixed && table.cell('fixed', print('(removed)'));
19
19
  table.newRow();
20
20
  }
21
21
  console.log(table.sort(['filePath', 'parentSymbol', 'symbol']).print().trim());
@@ -35,7 +35,7 @@ export default ({ report, issues, tagHints, configurationHints, noConfigHints, i
35
35
  for (const issue of issuesForType) {
36
36
  const relPath = toRelative(issue.filePath);
37
37
  if (issue.isFixed)
38
- console.log(picocolors.gray(`${relPath} (deleted)`));
38
+ console.log(picocolors.gray(`${relPath} (removed)`));
39
39
  else if (issue.severity === 'warn')
40
40
  console.log(picocolors.gray(relPath));
41
41
  else
@@ -27,6 +27,7 @@ interface BaseWorkspaceConfiguration {
27
27
  export interface WorkspaceConfiguration extends BaseWorkspaceConfiguration, Partial<PluginsConfiguration> {
28
28
  }
29
29
  type IgnorableExport = 'class' | 'enum' | 'function' | 'interface' | 'member' | 'type';
30
+ export type IgnoreExportsUsedInFile = boolean | Partial<Record<IgnorableExport, boolean>>;
30
31
  export interface Configuration {
31
32
  rules: Rules;
32
33
  include: IssueType[];
@@ -34,7 +35,7 @@ export interface Configuration {
34
35
  ignore: NormalizedGlob;
35
36
  ignoreBinaries: IgnorePatterns;
36
37
  ignoreDependencies: IgnorePatterns;
37
- ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
38
+ ignoreExportsUsedInFile: IgnoreExportsUsedInFile;
38
39
  ignoreMembers: IgnorePatterns;
39
40
  ignoreWorkspaces: string[];
40
41
  isIncludeEntryExports: boolean;
@@ -1,7 +1,7 @@
1
1
  import type ts from 'typescript';
2
2
  import type { SymbolType } from './issues.js';
3
3
  type Identifier = string;
4
- type ExportPosTuple = [number, number];
4
+ type ExportPosTuple = [number, number, number];
5
5
  export type Fix = ExportPosTuple | undefined;
6
6
  export type Fixes = Array<ExportPosTuple>;
7
7
  export type ExportNode = {
@@ -1,8 +1,11 @@
1
1
  import type ts from 'typescript';
2
- type SymbolTable = Map<string, ts.Symbol>;
2
+ type SymbolTable = Map<string, SymbolWithExportSymbol>;
3
3
  type SymbolWithExports = ts.Symbol & {
4
4
  exports?: SymbolTable;
5
5
  };
6
+ interface SymbolWithExportSymbol extends ts.Symbol {
7
+ exportSymbol?: ts.Symbol;
8
+ }
6
9
  type PragmaMap = {
7
10
  arguments: {
8
11
  factory?: string;
@@ -15,6 +18,12 @@ type PragmaMap = {
15
18
  pos?: number;
16
19
  };
17
20
  };
21
+ range?: {
22
+ kind?: number;
23
+ pos?: number;
24
+ end?: number;
25
+ hasTrailingNewLine?: boolean;
26
+ };
18
27
  };
19
28
  export interface BoundSourceFile extends ts.SourceFile {
20
29
  symbol?: SymbolWithExports;
@@ -20,6 +20,7 @@ export declare const getAccessMembers: (typeChecker: ts.TypeChecker, node: ts.Id
20
20
  export declare const isDestructuring: (node: ts.Node) => boolean;
21
21
  export declare const getDestructuredIds: (name: ts.ObjectBindingPattern) => string[];
22
22
  export declare const isConsiderReferencedNS: (node: ts.Identifier) => boolean;
23
+ export declare const isObjectEnumerationCallExpressionArgument: (node: ts.Identifier) => boolean;
23
24
  export declare const isTopLevel: (node: ts.Node) => boolean;
24
25
  export declare const getTypeName: (node: ts.Identifier) => ts.QualifiedName | undefined;
25
26
  export declare const isImportSpecifier: (node: ts.Node) => boolean;
@@ -133,12 +133,20 @@ export const isDestructuring = (node) => node.parent &&
133
133
  ts.isVariableDeclarationList(node.parent.parent) &&
134
134
  ts.isObjectBindingPattern(node.parent.name);
135
135
  export const getDestructuredIds = (name) => name.elements.map(element => element.name.getText());
136
- export const isConsiderReferencedNS = (node) => ts.isShorthandPropertyAssignment(node.parent) ||
136
+ export const isConsiderReferencedNS = (node) => ts.isPropertyAssignment(node.parent) ||
137
+ ts.isShorthandPropertyAssignment(node.parent) ||
137
138
  (ts.isCallExpression(node.parent) && node.parent.arguments.includes(node)) ||
138
139
  ts.isSpreadAssignment(node.parent) ||
139
140
  ts.isExportAssignment(node.parent) ||
140
141
  (ts.isVariableDeclaration(node.parent) && node.parent.initializer === node) ||
141
142
  ts.isTypeQueryNode(node.parent);
143
+ const objectEnumerationMethods = new Set(['keys', 'entries', 'values', 'getOwnPropertyNames']);
144
+ export const isObjectEnumerationCallExpressionArgument = (node) => ts.isCallExpression(node.parent) &&
145
+ node.parent.arguments.includes(node) &&
146
+ ts.isPropertyAccessExpression(node.parent.expression) &&
147
+ ts.isIdentifier(node.parent.expression.expression) &&
148
+ node.parent.expression.expression.escapedText === 'Object' &&
149
+ objectEnumerationMethods.has(String(node.parent.expression.name.escapedText));
142
150
  export const isTopLevel = (node) => ts.isSourceFile(node.parent) || (node.parent && ts.isSourceFile(node.parent.parent));
143
151
  export const getTypeName = (node) => {
144
152
  if (!node.parent?.parent)
@@ -1,3 +1,4 @@
1
1
  import ts from 'typescript';
2
2
  import type { Export, ExportMember } from '../types/dependency-graph.js';
3
+ export declare const isType: (item: Export | ExportMember) => boolean;
3
4
  export declare const findInternalReferences: (item: Export | ExportMember, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker, referencedSymbolsInExportedTypes: Set<ts.Symbol>) => [number, boolean];
@@ -1,9 +1,11 @@
1
1
  import ts from 'typescript';
2
2
  import { isIdChar } from '../util/regex.js';
3
- const isType = (item) => item.type === 'type' || item.type === 'interface' || item.type === 'member';
3
+ export const isType = (item) => item.type === 'type' || item.type === 'interface' || item.type === 'enum';
4
4
  export const findInternalReferences = (item, sourceFile, typeChecker, referencedSymbolsInExportedTypes) => {
5
5
  if (!item.symbol)
6
6
  return [0, false];
7
+ if (item.identifier === '')
8
+ return [1, false];
7
9
  if (item.symbol.flags & ts.SymbolFlags.AliasExcludes)
8
10
  return [1, false];
9
11
  const text = sourceFile.text;
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript';
2
2
  import type { Tags } from '../types/cli.js';
3
+ import type { IgnoreExportsUsedInFile } from '../types/config.js';
3
4
  import type { ExportMap, ImportMap, UnresolvedImport } from '../types/dependency-graph.js';
4
5
  import type { IssueSymbol } from '../types/issues.js';
5
6
  import type { BoundSourceFile } from './SourceFile.js';
@@ -9,7 +10,7 @@ export type GetImportsAndExportsOptions = {
9
10
  isFixExports: boolean;
10
11
  isFixTypes: boolean;
11
12
  isReportClassMembers: boolean;
12
- ignoreExportsUsedInFile: boolean;
13
+ ignoreExportsUsedInFile: IgnoreExportsUsedInFile;
13
14
  tags: Tags;
14
15
  };
15
16
  export declare const _getImportsAndExports: (sourceFile: BoundSourceFile, resolveModule: (specifier: string) => ts.ResolvedModuleFull | undefined, typeChecker: ts.TypeChecker, options: GetImportsAndExportsOptions) => {