knip 5.65.0 → 5.66.1

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 (55) hide show
  1. package/dist/ConfigurationChief.d.ts +12 -6
  2. package/dist/ConfigurationChief.js +2 -0
  3. package/dist/ConsoleStreamer.d.ts +2 -1
  4. package/dist/ConsoleStreamer.js +10 -5
  5. package/dist/IssueCollector.d.ts +8 -1
  6. package/dist/IssueCollector.js +40 -5
  7. package/dist/compilers/index.d.ts +15 -11
  8. package/dist/constants.d.ts +28 -3
  9. package/dist/constants.js +10 -0
  10. package/dist/graph/build.js +2 -1
  11. package/dist/index.js +6 -1
  12. package/dist/plugins/danger/index.d.ts +8 -0
  13. package/dist/plugins/danger/index.js +11 -0
  14. package/dist/plugins/eleventy/helpers.d.ts +1 -0
  15. package/dist/plugins/eleventy/helpers.js +1 -0
  16. package/dist/plugins/index.d.ts +6 -0
  17. package/dist/plugins/index.js +2 -0
  18. package/dist/plugins/nuxt/index.js +5 -1
  19. package/dist/reporters/util/util.d.ts +2 -2
  20. package/dist/reporters/util/util.js +2 -3
  21. package/dist/reporters/watch.d.ts +2 -2
  22. package/dist/reporters/watch.js +3 -3
  23. package/dist/schema/configuration.d.ts +12 -6
  24. package/dist/schema/configuration.js +5 -8
  25. package/dist/schema/plugins.d.ts +5 -0
  26. package/dist/schema/plugins.js +1 -0
  27. package/dist/types/PluginNames.d.ts +2 -2
  28. package/dist/types/PluginNames.js +1 -0
  29. package/dist/types/config.d.ts +4 -2
  30. package/dist/types/issues.d.ts +2 -10
  31. package/dist/types/issues.js +1 -11
  32. package/dist/typescript/ast-helpers.d.ts +3 -3
  33. package/dist/typescript/ast-helpers.js +11 -12
  34. package/dist/typescript/visitors/exports/exportDeclaration.js +4 -5
  35. package/dist/typescript/visitors/exports/exportKeyword.js +9 -10
  36. package/dist/typescript/visitors/exports/exportsAccessExpression.js +2 -3
  37. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +5 -6
  38. package/dist/util/Performance.d.ts +1 -1
  39. package/dist/util/Performance.js +2 -2
  40. package/dist/util/create-options.d.ts +17 -13
  41. package/dist/util/create-options.js +1 -1
  42. package/dist/util/fs.d.ts +2 -1
  43. package/dist/util/fs.js +14 -4
  44. package/dist/util/get-included-issue-types.js +1 -4
  45. package/dist/util/get-referenced-inputs.d.ts +2 -2
  46. package/dist/util/get-referenced-inputs.js +5 -5
  47. package/dist/util/has-strictly-ns-references.d.ts +1 -1
  48. package/dist/util/loader.js +6 -3
  49. package/dist/util/string.js +5 -1
  50. package/dist/util/watch.d.ts +7 -3
  51. package/dist/util/watch.js +106 -67
  52. package/dist/version.d.ts +1 -1
  53. package/dist/version.js +1 -1
  54. package/package.json +1 -1
  55. package/schema.json +20 -0
@@ -147,6 +147,11 @@ export declare class ConfigurationChief {
147
147
  entry?: string | string[] | undefined;
148
148
  project?: string | string[] | undefined;
149
149
  } | undefined;
150
+ danger?: string | boolean | string[] | {
151
+ config?: string | string[] | undefined;
152
+ entry?: string | string[] | undefined;
153
+ project?: string | string[] | undefined;
154
+ } | undefined;
150
155
  'dependency-cruiser'?: string | boolean | string[] | {
151
156
  config?: string | string[] | undefined;
152
157
  entry?: string | string[] | undefined;
@@ -639,13 +644,18 @@ export declare class ConfigurationChief {
639
644
  ignoreUnresolved: (string | RegExp)[];
640
645
  };
641
646
  getConfigForWorkspace(workspaceName: string, extensions?: string[]): {
647
+ bun?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
648
+ node?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
649
+ pnpm?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
650
+ yarn?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
651
+ typescript?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
652
+ jest?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
642
653
  angular?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
643
654
  astro?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
644
655
  ava?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
645
656
  babel?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
646
657
  biome?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
647
658
  bumpp?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
648
- bun?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
649
659
  c8?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
650
660
  capacitor?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
651
661
  changelogen?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -658,6 +668,7 @@ export declare class ConfigurationChief {
658
668
  cspell?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
659
669
  cucumber?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
660
670
  cypress?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
671
+ danger?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
661
672
  "dependency-cruiser"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
662
673
  docusaurus?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
663
674
  dotenv?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -673,7 +684,6 @@ export declare class ConfigurationChief {
673
684
  hardhat?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
674
685
  husky?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
675
686
  "i18next-parser"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
676
- jest?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
677
687
  karma?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
678
688
  ladle?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
679
689
  lefthook?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -690,7 +700,6 @@ export declare class ConfigurationChief {
690
700
  nest?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
691
701
  netlify?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
692
702
  next?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
693
- node?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
694
703
  "node-modules-inspector"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
695
704
  nodemon?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
696
705
  "npm-package-json-lint"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -703,7 +712,6 @@ export declare class ConfigurationChief {
703
712
  "playwright-ct"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
704
713
  "playwright-test"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
705
714
  plop?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
706
- pnpm?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
707
715
  postcss?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
708
716
  preconstruct?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
709
717
  prettier?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -738,7 +746,6 @@ export declare class ConfigurationChief {
738
746
  tsup?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
739
747
  tsx?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
740
748
  typedoc?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
741
- typescript?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
742
749
  unbuild?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
743
750
  unocss?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
744
751
  "vercel-og"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -751,7 +758,6 @@ export declare class ConfigurationChief {
751
758
  wireit?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
752
759
  wrangler?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
753
760
  xo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
754
- yarn?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
755
761
  yorkie?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
756
762
  entry: string[];
757
763
  project: string[];
@@ -98,6 +98,7 @@ export class ConfigurationChief {
98
98
  const ignoreMembers = rawConfig.ignoreMembers ?? [];
99
99
  const ignoreUnresolved = rawConfig.ignoreUnresolved ?? [];
100
100
  const ignoreExportsUsedInFile = rawConfig.ignoreExportsUsedInFile ?? false;
101
+ const ignoreIssues = rawConfig.ignoreIssues;
101
102
  const ignoreWorkspaces = rawConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
102
103
  const isIncludeEntryExports = rawConfig.includeEntryExports ?? this.isIncludeEntryExports;
103
104
  const { syncCompilers, asyncCompilers } = rawConfig;
@@ -115,6 +116,7 @@ export class ConfigurationChief {
115
116
  ignoreMembers,
116
117
  ignoreUnresolved,
117
118
  ignoreExportsUsedInFile,
119
+ ignoreIssues,
118
120
  ignoreWorkspaces,
119
121
  isIncludeEntryExports,
120
122
  syncCompilers: new Map(Object.entries(syncCompilers ?? {})),
@@ -1,10 +1,11 @@
1
1
  import type { MainOptions } from './util/create-options.js';
2
2
  export declare class ConsoleStreamer {
3
3
  isEnabled: boolean;
4
+ isWatch: boolean;
4
5
  private lines;
5
6
  constructor(options: MainOptions);
6
7
  private clearLines;
7
- private resetLines;
8
+ private clearScreen;
8
9
  private update;
9
10
  cast(message: string | string[], sub?: string): void;
10
11
  clear(): void;
@@ -1,8 +1,10 @@
1
1
  export class ConsoleStreamer {
2
2
  isEnabled = false;
3
+ isWatch = false;
3
4
  lines = 0;
4
5
  constructor(options) {
5
- this.isEnabled = options.isShowProgress;
6
+ this.isEnabled = options.isShowProgress && !options.isDebug;
7
+ this.isWatch = options.isWatch;
6
8
  }
7
9
  clearLines(count) {
8
10
  if (count > 0) {
@@ -13,11 +15,11 @@ export class ConsoleStreamer {
13
15
  }
14
16
  process.stdout.cursorTo(0);
15
17
  }
16
- resetLines() {
17
- this.clearLines(this.lines);
18
+ clearScreen() {
19
+ process.stdout.write('\x1b[2J\x1b[1;1f');
18
20
  }
19
21
  update(messages) {
20
- this.resetLines();
22
+ this.clear();
21
23
  process.stdout.write(`${messages.join('\n')}\n`);
22
24
  this.lines = messages.length;
23
25
  }
@@ -32,6 +34,9 @@ export class ConsoleStreamer {
32
34
  clear() {
33
35
  if (!this.isEnabled)
34
36
  return;
35
- this.resetLines();
37
+ if (this.isWatch)
38
+ this.clearScreen();
39
+ else
40
+ this.clearLines(this.lines);
36
41
  }
37
42
  }
@@ -1,3 +1,4 @@
1
+ import type { IgnoreIssues } from './types/config.js';
1
2
  import type { ConfigurationHint, Issue, TagHint } from './types/issues.js';
2
3
  import type { MainOptions } from './util/create-options.js';
3
4
  export declare class IssueCollector {
@@ -13,15 +14,18 @@ export declare class IssueCollector {
13
14
  private ignoreFilesPatterns;
14
15
  private isMatch;
15
16
  private isFileMatch;
17
+ private issueMatchers;
16
18
  constructor(options: MainOptions);
17
19
  addIgnorePatterns(patterns: string[]): void;
18
20
  addIgnoreFilesPatterns(patterns: string[]): void;
21
+ setIgnoreIssues(ignoreIssues?: IgnoreIssues): void;
22
+ private shouldIgnoreIssue;
19
23
  addFileCounts({ processed, unused }: {
20
24
  processed: number;
21
25
  unused: number;
22
26
  }): void;
23
27
  addFilesIssues(filePaths: string[]): void;
24
- addIssue(issue: Issue): Issue | undefined;
28
+ addIssue(issue: Issue): true | undefined;
25
29
  addConfigurationHint(issue: ConfigurationHint): void;
26
30
  addTagHint(issue: TagHint): void;
27
31
  purge(): import("./types/issues.js").IssueSet;
@@ -31,4 +35,7 @@ export declare class IssueCollector {
31
35
  tagHints: Set<TagHint>;
32
36
  configurationHints: Set<ConfigurationHint>;
33
37
  };
38
+ private retainedIssues;
39
+ retainIssue(issue: Issue): void;
40
+ getRetainedIssues(): Issue[];
34
41
  }
@@ -16,6 +16,7 @@ export class IssueCollector {
16
16
  ignoreFilesPatterns = new Set();
17
17
  isMatch;
18
18
  isFileMatch;
19
+ issueMatchers = new Map();
19
20
  constructor(options) {
20
21
  this.cwd = options.cwd;
21
22
  this.rules = options.rules;
@@ -26,14 +27,37 @@ export class IssueCollector {
26
27
  addIgnorePatterns(patterns) {
27
28
  for (const pattern of patterns)
28
29
  this.ignorePatterns.add(pattern);
29
- const _patterns = Array.from(this.ignorePatterns);
30
- this.isMatch = (filePath) => isMatch(filePath, _patterns, { dot: true });
30
+ const p = [...this.ignorePatterns];
31
+ this.isMatch = (filePath) => isMatch(filePath, p, { dot: true });
31
32
  }
32
33
  addIgnoreFilesPatterns(patterns) {
33
34
  for (const pattern of patterns)
34
35
  this.ignoreFilesPatterns.add(pattern);
35
- const _patterns = Array.from(this.ignoreFilesPatterns);
36
- this.isFileMatch = (filePath) => isMatch(filePath, _patterns, { dot: true });
36
+ const p = [...this.ignoreFilesPatterns];
37
+ this.isFileMatch = (filePath) => isMatch(filePath, p, { dot: true });
38
+ }
39
+ setIgnoreIssues(ignoreIssues) {
40
+ if (!ignoreIssues)
41
+ return;
42
+ const issueTypePatterns = new Map();
43
+ for (const [pattern, issueTypes] of Object.entries(ignoreIssues)) {
44
+ for (const issueType of issueTypes) {
45
+ if (!issueTypePatterns.has(issueType)) {
46
+ issueTypePatterns.set(issueType, []);
47
+ }
48
+ issueTypePatterns.get(issueType)?.push(pattern);
49
+ }
50
+ }
51
+ for (const [issueType, patterns] of issueTypePatterns) {
52
+ this.issueMatchers.set(issueType, (filePath) => isMatch(filePath, patterns, { dot: true }));
53
+ }
54
+ }
55
+ shouldIgnoreIssue(filePath, issueType) {
56
+ const matcher = this.issueMatchers.get(issueType);
57
+ if (!matcher)
58
+ return false;
59
+ const relativePath = relative(this.cwd, filePath);
60
+ return matcher(relativePath);
37
61
  }
38
62
  addFileCounts({ processed, unused }) {
39
63
  this.counters.processed += processed;
@@ -49,6 +73,8 @@ export class IssueCollector {
49
73
  continue;
50
74
  if (this.isFileMatch(filePath))
51
75
  continue;
76
+ if (this.shouldIgnoreIssue(filePath, 'files'))
77
+ continue;
52
78
  this.issues.files.add(filePath);
53
79
  const symbol = relative(this.cwd, filePath);
54
80
  this.issues._files[symbol] = [{ type: 'files', filePath, symbol, severity: this.rules.files }];
@@ -61,6 +87,8 @@ export class IssueCollector {
61
87
  return;
62
88
  if (this.isMatch(issue.filePath))
63
89
  return;
90
+ if (this.shouldIgnoreIssue(issue.filePath, issue.type))
91
+ return;
64
92
  const key = relative(this.cwd, issue.filePath);
65
93
  const { type } = issue;
66
94
  issue.severity = this.rules[type];
@@ -71,7 +99,7 @@ export class IssueCollector {
71
99
  issues[key][symbol] = issue;
72
100
  this.counters[issue.type]++;
73
101
  }
74
- return issue;
102
+ return true;
75
103
  }
76
104
  addConfigurationHint(issue) {
77
105
  const key = `${issue.workspaceName}::${issue.type}::${issue.identifier}`;
@@ -95,4 +123,11 @@ export class IssueCollector {
95
123
  configurationHints: new Set(this.configurationHints.values()),
96
124
  };
97
125
  }
126
+ retainedIssues = [];
127
+ retainIssue(issue) {
128
+ this.retainedIssues.push(issue);
129
+ }
130
+ getRetainedIssues() {
131
+ return this.retainedIssues;
132
+ }
98
133
  }
@@ -99,6 +99,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
99
99
  entry?: string | string[] | undefined;
100
100
  project?: string | string[] | undefined;
101
101
  } | undefined;
102
+ danger?: string | boolean | string[] | {
103
+ config?: string | string[] | undefined;
104
+ entry?: string | string[] | undefined;
105
+ project?: string | string[] | undefined;
106
+ } | undefined;
102
107
  'dependency-cruiser'?: string | boolean | string[] | {
103
108
  config?: string | string[] | undefined;
104
109
  entry?: string | string[] | undefined;
@@ -670,6 +675,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
670
675
  entry?: string | string[] | undefined;
671
676
  project?: string | string[] | undefined;
672
677
  } | undefined;
678
+ danger?: string | boolean | string[] | {
679
+ config?: string | string[] | undefined;
680
+ entry?: string | string[] | undefined;
681
+ project?: string | string[] | undefined;
682
+ } | undefined;
673
683
  'dependency-cruiser'?: string | boolean | string[] | {
674
684
  config?: string | string[] | undefined;
675
685
  entry?: string | string[] | undefined;
@@ -1156,10 +1166,10 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1156
1166
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1157
1167
  includeEntryExports?: boolean | undefined;
1158
1168
  }> | undefined;
1159
- include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
1160
- exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
1169
+ include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[] | undefined;
1170
+ exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[] | undefined;
1161
1171
  $schema?: string | undefined;
1162
- rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
1172
+ rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates", "error" | "warn" | "off">> | undefined;
1163
1173
  entry?: string | string[] | undefined;
1164
1174
  project?: string | string[] | undefined;
1165
1175
  paths?: Record<string, string[]> | undefined;
@@ -1169,14 +1179,8 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1169
1179
  ignoreDependencies?: (string | RegExp)[] | undefined;
1170
1180
  ignoreMembers?: (string | RegExp)[] | undefined;
1171
1181
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1172
- ignoreExportsUsedInFile?: boolean | {
1173
- class?: boolean | undefined;
1174
- enum?: boolean | undefined;
1175
- function?: boolean | undefined;
1176
- interface?: boolean | undefined;
1177
- member?: boolean | undefined;
1178
- type?: boolean | undefined;
1179
- } | undefined;
1182
+ ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
1183
+ ignoreIssues?: Record<string, ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "nsExports" | "types" | "nsTypes" | "enumMembers" | "classMembers" | "duplicates")[]> | undefined;
1180
1184
  ignoreWorkspaces?: string[] | undefined;
1181
1185
  includeEntryExports?: boolean | undefined;
1182
1186
  compilers?: Record<string, true | ((filename: string, contents: string) => string) | ((filename: string, contents: string) => Promise<string>)> | undefined;
@@ -1,4 +1,3 @@
1
- import type { IssueType } from './types/issues.js';
2
1
  export declare const ROOT_WORKSPACE_NAME = ".";
3
2
  export declare const IMPORT_STAR = "*";
4
3
  export declare const ANONYMOUS = "__anonymous";
@@ -16,8 +15,34 @@ export declare const IGNORED_DEPENDENCIES: Set<string>;
16
15
  export declare const IGNORED_RUNTIME_DEPENDENCIES: Set<string>;
17
16
  export declare const FOREIGN_FILE_EXTENSIONS: Set<string>;
18
17
  export declare const IGNORE_DEFINITELY_TYPED: Set<string>;
19
- export declare const ISSUE_TYPES: IssueType[];
20
- export declare const ISSUE_TYPE_TITLE: Record<IssueType, string>;
18
+ export declare const ISSUE_TYPES: readonly ["files", "dependencies", "devDependencies", "optionalPeerDependencies", "unlisted", "binaries", "unresolved", "exports", "nsExports", "types", "nsTypes", "enumMembers", "classMembers", "duplicates"];
19
+ export declare const ISSUE_TYPE_TITLE: {
20
+ readonly files: "Unused files";
21
+ readonly _files: "Unused files";
22
+ readonly dependencies: "Unused dependencies";
23
+ readonly devDependencies: "Unused devDependencies";
24
+ readonly optionalPeerDependencies: "Referenced optional peerDependencies";
25
+ readonly unlisted: "Unlisted dependencies";
26
+ readonly binaries: "Unlisted binaries";
27
+ readonly unresolved: "Unresolved imports";
28
+ readonly exports: "Unused exports";
29
+ readonly nsExports: "Exports in used namespace";
30
+ readonly types: "Unused exported types";
31
+ readonly nsTypes: "Exported types in used namespace";
32
+ readonly enumMembers: "Unused exported enum members";
33
+ readonly classMembers: "Unused exported class members";
34
+ readonly duplicates: "Duplicate exports";
35
+ };
36
+ export declare const SYMBOL_TYPE: {
37
+ readonly CLASS: "class";
38
+ readonly ENUM: "enum";
39
+ readonly FUNCTION: "function";
40
+ readonly INTERFACE: "interface";
41
+ readonly MEMBER: "member";
42
+ readonly TYPE: "type";
43
+ readonly UNKNOWN: "unknown";
44
+ readonly VARIABLE: "variable";
45
+ };
21
46
  export declare const FIX_FLAGS: {
22
47
  readonly NONE: 0;
23
48
  readonly OBJECT_BINDING: number;
package/dist/constants.js CHANGED
@@ -190,6 +190,16 @@ export const ISSUE_TYPE_TITLE = {
190
190
  classMembers: 'Unused exported class members',
191
191
  duplicates: 'Duplicate exports',
192
192
  };
193
+ export const SYMBOL_TYPE = {
194
+ CLASS: 'class',
195
+ ENUM: 'enum',
196
+ FUNCTION: 'function',
197
+ INTERFACE: 'interface',
198
+ MEMBER: 'member',
199
+ TYPE: 'type',
200
+ UNKNOWN: 'unknown',
201
+ VARIABLE: 'variable',
202
+ };
193
203
  export const FIX_FLAGS = {
194
204
  NONE: 0,
195
205
  OBJECT_BINDING: 1 << 0,
@@ -18,7 +18,8 @@ export async function build({ chief, collector, deputy, factory, isGitIgnored, s
18
18
  const enabledPluginsStore = new Map();
19
19
  const toSourceFilePath = getToSourcePathHandler(chief);
20
20
  const toSourceFilePaths = getToSourcePathsHandler(chief);
21
- const getReferencedInternalFilePath = getReferencedInputsHandler(collector, deputy, chief, isGitIgnored);
21
+ const addIssue = (issue) => collector.addIssue(issue) && options.isWatch && collector.retainIssue(issue);
22
+ const getReferencedInternalFilePath = getReferencedInputsHandler(deputy, chief, isGitIgnored, addIssue);
22
23
  for (const workspace of workspaces) {
23
24
  const { name, dir, manifestPath, manifestStr } = workspace;
24
25
  const manifest = chief.getManifestForWorkspace(name);
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { build } from './graph/build.js';
8
8
  import { IssueCollector } from './IssueCollector.js';
9
9
  import { IssueFixer } from './IssueFixer.js';
10
10
  import { PrincipalFactory } from './PrincipalFactory.js';
11
+ import watchReporter from './reporters/watch.js';
11
12
  import { debugLogArray, debugLogObject } from './util/debug.js';
12
13
  import { getGitIgnoredHandler } from './util/glob-core.js';
13
14
  import { getWatchHandler } from './util/watch.js';
@@ -24,6 +25,7 @@ export const main = async (options) => {
24
25
  streamer.cast('Reading workspace configuration');
25
26
  const workspaces = await chief.getWorkspaces();
26
27
  const isGitIgnored = await getGitIgnoredHandler(options);
28
+ collector.setIgnoreIssues(chief.config.ignoreIssues);
27
29
  debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
28
30
  debugLogObject('*', 'Included workspace configs', () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors })));
29
31
  const { graph, entryPaths, analyzedFiles, unreferencedFiles, analyzeSourceFile } = await build({
@@ -51,6 +53,9 @@ export const main = async (options) => {
51
53
  });
52
54
  if (options.isWatch) {
53
55
  const isIgnored = (filePath) => filePath.startsWith(options.cacheLocation) || filePath.includes('/.git/') || isGitIgnored(filePath);
56
+ const onUpdate = options.isWatch
57
+ ? ({ issues, duration }) => watchReporter(options, { issues, streamer, size: analyzedFiles.size, duration })
58
+ : () => { };
54
59
  const watchHandler = await getWatchHandler(options, {
55
60
  analyzedFiles,
56
61
  analyzeSourceFile,
@@ -60,7 +65,7 @@ export const main = async (options) => {
60
65
  factory,
61
66
  graph,
62
67
  isIgnored,
63
- streamer,
68
+ onUpdate,
64
69
  unreferencedFiles,
65
70
  });
66
71
  watch('.', { recursive: true }, watchHandler);
@@ -0,0 +1,8 @@
1
+ import type { IsPluginEnabled } from '../../types/config.js';
2
+ declare const _default: {
3
+ title: string;
4
+ enablers: string[];
5
+ isEnabled: IsPluginEnabled;
6
+ entry: string[];
7
+ };
8
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ const title = 'Danger';
3
+ const enablers = ['danger'];
4
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
+ const entry = ['dangerfile.{js,cjs,mjs,ts}'];
6
+ export default {
7
+ title,
8
+ enablers,
9
+ isEnabled,
10
+ entry,
11
+ };
@@ -82,6 +82,7 @@ export declare class DummyEleventyConfig {
82
82
  setLayoutsDirectory(): void;
83
83
  setFreezeReservedData(): void;
84
84
  addDateParsing(): void;
85
+ addBundle(): void;
85
86
  _uniqueId: {};
86
87
  events: {};
87
88
  benchmarkManager: {};
@@ -91,6 +91,7 @@ export class DummyEleventyConfig {
91
91
  setLayoutsDirectory() { }
92
92
  setFreezeReservedData() { }
93
93
  addDateParsing() { }
94
+ addBundle() { }
94
95
  _uniqueId = {};
95
96
  events = {};
96
97
  benchmarkManager = {};
@@ -141,6 +141,12 @@ export declare const Plugins: {
141
141
  entry: string[];
142
142
  resolveConfig: import("../types/config.js").ResolveConfig<import("./cypress/types.js").CypressConfig>;
143
143
  };
144
+ danger: {
145
+ title: string;
146
+ enablers: string[];
147
+ isEnabled: import("../types/config.js").IsPluginEnabled;
148
+ entry: string[];
149
+ };
144
150
  'dependency-cruiser': {
145
151
  title: string;
146
152
  enablers: string[];
@@ -17,6 +17,7 @@ import { default as createTypescriptApp } from './create-typescript-app/index.js
17
17
  import { default as cspell } from './cspell/index.js';
18
18
  import { default as cucumber } from './cucumber/index.js';
19
19
  import { default as cypress } from './cypress/index.js';
20
+ import { default as danger } from './danger/index.js';
20
21
  import { default as dependencyCruiser } from './dependency-cruiser/index.js';
21
22
  import { default as docusaurus } from './docusaurus/index.js';
22
23
  import { default as dotenv } from './dotenv/index.js';
@@ -132,6 +133,7 @@ export const Plugins = {
132
133
  cspell,
133
134
  cucumber,
134
135
  cypress,
136
+ danger,
135
137
  'dependency-cruiser': dependencyCruiser,
136
138
  docusaurus,
137
139
  dotenv,
@@ -18,7 +18,11 @@ const production = [
18
18
  ];
19
19
  const setup = async () => {
20
20
  if (globalThis && !('defineNuxtConfig' in globalThis)) {
21
- Object.defineProperty(globalThis, 'defineNuxtConfig', { value: (id) => id });
21
+ Object.defineProperty(globalThis, 'defineNuxtConfig', {
22
+ value: (id) => id,
23
+ writable: true,
24
+ configurable: true,
25
+ });
22
26
  }
23
27
  };
24
28
  const resolveConfig = async (localConfig) => {
@@ -1,9 +1,9 @@
1
1
  import { ISSUE_TYPE_TITLE } from '../../constants.js';
2
- import { type Issue, type IssueSeverity, type IssueSymbol } from '../../types/issues.js';
2
+ import type { Issue, IssueSeverity, IssueSymbol } from '../../types/issues.js';
3
3
  import { Table } from '../../util/table.js';
4
4
  export declare const dim: import("picocolors/types.js").Formatter;
5
5
  export declare const bright: import("picocolors/types.js").Formatter;
6
- export declare const getIssueTypeTitle: (reportType: keyof typeof ISSUE_TYPE_TITLE) => string;
6
+ export declare const getIssueTypeTitle: (reportType: keyof typeof ISSUE_TYPE_TITLE) => "Unused files" | "Unused dependencies" | "Unused devDependencies" | "Referenced optional peerDependencies" | "Unlisted dependencies" | "Unlisted binaries" | "Unresolved imports" | "Unused exports" | "Exports in used namespace" | "Unused exported types" | "Exported types in used namespace" | "Unused exported enum members" | "Unused exported class members" | "Duplicate exports";
7
7
  export declare const getColoredTitle: (title: string, count: number) => string;
8
8
  export declare const getDimmedTitle: (title: string, count: number) => string;
9
9
  type LogIssueLine = {
@@ -1,6 +1,5 @@
1
1
  import picocolors from 'picocolors';
2
- import { ISSUE_TYPE_TITLE } from '../../constants.js';
3
- import { SymbolType } from '../../types/issues.js';
2
+ import { ISSUE_TYPE_TITLE, SYMBOL_TYPE } from '../../constants.js';
4
3
  import { relative } from '../../util/path.js';
5
4
  import { Table } from '../../util/table.js';
6
5
  const plain = (text) => text;
@@ -47,7 +46,7 @@ export const getTableForType = (issues, cwd, options = { isUseColors: true }) =>
47
46
  const symbol = issue.symbols ? issue.symbols.map(s => s.symbol).join(', ') : issue.symbol;
48
47
  table.cell('symbol', print(symbol), options.isUseColors ? highlightSymbol(issue) : () => symbol);
49
48
  table.cell('parentSymbol', issue.parentSymbol && print(issue.parentSymbol));
50
- table.cell('symbolType', issue.symbolType && issue.symbolType !== SymbolType.UNKNOWN && print(issue.symbolType));
49
+ table.cell('symbolType', issue.symbolType && issue.symbolType !== SYMBOL_TYPE.UNKNOWN && print(issue.symbolType));
51
50
  const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
52
51
  const cell = issue.type === 'files' ? '' : `${relative(cwd, issue.filePath)}${pos}`;
53
52
  table.cell('filePath', print(cell));
@@ -4,8 +4,8 @@ import type { MainOptions } from '../util/create-options.js';
4
4
  interface WatchReporter {
5
5
  issues: Issues;
6
6
  streamer: ConsoleStreamer;
7
- startTime?: number;
7
+ duration?: number;
8
8
  size: number;
9
9
  }
10
- declare const _default: (options: MainOptions, { issues, streamer, startTime, size }: WatchReporter) => void;
10
+ declare const _default: (options: MainOptions, { issues, streamer, duration, size }: WatchReporter) => void;
11
11
  export default _default;
@@ -2,7 +2,7 @@ import picocolors from 'picocolors';
2
2
  import { perfObserver } from '../util/Performance.js';
3
3
  import { prettyMilliseconds } from '../util/string.js';
4
4
  import { getIssueTypeTitle, getTableForType } from './util/util.js';
5
- export default (options, { issues, streamer, startTime, size }) => {
5
+ export default (options, { issues, streamer, duration, size }) => {
6
6
  const reportMultipleGroups = Object.values(options.includedIssueTypes).filter(Boolean).length > 1;
7
7
  let totalIssues = 0;
8
8
  const lines = [];
@@ -22,8 +22,8 @@ export default (options, { issues, streamer, startTime, size }) => {
22
22
  }
23
23
  }
24
24
  const mem = perfObserver.getCurrentMemUsageInMb();
25
- const duration = perfObserver.getCurrentDurationInMs(startTime);
26
- const summary = `${size} files in ${prettyMilliseconds(duration)} (${mem}MB)`;
25
+ const ms = duration ?? perfObserver.getCurrentDurationInMs();
26
+ const summary = `${size} files in ${prettyMilliseconds(ms)} (${mem}MB)`;
27
27
  const messages = totalIssues === 0
28
28
  ? ['✂️ Excellent, Knip found no issues.', '', picocolors.gray(summary)]
29
29
  : [...lines, '', picocolors.gray(summary)];
@@ -97,6 +97,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
97
97
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
98
98
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
99
99
  }, z.core.$strip>]>>;
100
+ danger: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
101
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
102
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
103
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
104
+ }, z.core.$strip>]>>;
100
105
  'dependency-cruiser': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
101
106
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
102
107
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -668,6 +673,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
668
673
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
669
674
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
670
675
  }, z.core.$strip>]>>;
676
+ danger: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
677
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
678
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
679
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
680
+ }, z.core.$strip>]>>;
671
681
  'dependency-cruiser': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
672
682
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
673
683
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -1172,13 +1182,9 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
1172
1182
  ignoreMembers: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniCustom<RegExp, RegExp>]>>>;
1173
1183
  ignoreUnresolved: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniCustom<RegExp, RegExp>]>>>;
1174
1184
  ignoreExportsUsedInFile: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniObject<{
1175
- class: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1176
- enum: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1177
- function: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1178
- interface: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1179
- member: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1180
- type: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1185
+ [k: string]: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1181
1186
  }, z.core.$strict>]>>;
1187
+ ignoreIssues: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniLiteral<"files">, z.ZodMiniLiteral<"dependencies">, z.ZodMiniLiteral<"devDependencies">, z.ZodMiniLiteral<"optionalPeerDependencies">, z.ZodMiniLiteral<"unlisted">, z.ZodMiniLiteral<"binaries">, z.ZodMiniLiteral<"unresolved">, z.ZodMiniLiteral<"exports">, z.ZodMiniLiteral<"types">, z.ZodMiniLiteral<"nsExports">, z.ZodMiniLiteral<"nsTypes">, z.ZodMiniLiteral<"duplicates">, z.ZodMiniLiteral<"enumMembers">, z.ZodMiniLiteral<"classMembers">]>>>>;
1182
1188
  ignoreWorkspaces: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
1183
1189
  includeEntryExports: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
1184
1190
  compilers: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnion<readonly [z.ZodMiniUnion<readonly [z.ZodMiniLiteral<true>, z.ZodMiniCustom<SyncCompiler, SyncCompiler>]>, z.ZodMiniCustom<AsyncCompiler, AsyncCompiler>]>>>;