knip 5.63.0 → 5.64.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/CacheConsultant.d.ts +3 -9
- package/dist/CacheConsultant.js +5 -5
- package/dist/ConfigurationChief.d.ts +597 -38
- package/dist/ConfigurationChief.js +33 -122
- package/dist/ConsoleStreamer.d.ts +2 -3
- package/dist/ConsoleStreamer.js +2 -2
- package/dist/DependencyDeputy.d.ts +2 -6
- package/dist/DependencyDeputy.js +3 -2
- package/dist/IssueCollector.d.ts +4 -12
- package/dist/IssueCollector.js +9 -9
- package/dist/IssueFixer.d.ts +3 -14
- package/dist/IssueFixer.js +14 -22
- package/dist/PrincipalFactory.d.ts +3 -2
- package/dist/PrincipalFactory.js +11 -11
- package/dist/ProjectPrincipal.d.ts +4 -3
- package/dist/ProjectPrincipal.js +8 -8
- package/dist/WorkspaceWorker.d.ts +4 -9
- package/dist/WorkspaceWorker.js +8 -12
- package/dist/binaries/bash-parser.d.ts +1 -0
- package/dist/binaries/bash-parser.js +4 -1
- package/dist/binaries/fallback.js +3 -2
- package/dist/binaries/package-manager/bun.js +1 -0
- package/dist/binaries/package-manager/pnpm.js +6 -1
- package/dist/binaries/plugins.js +3 -1
- package/dist/cli.js +43 -61
- package/dist/compilers/index.d.ts +34 -4
- package/dist/constants.js +2 -0
- package/dist/graph/analyze.d.ts +3 -8
- package/dist/graph/analyze.js +31 -31
- package/dist/graph/build.d.ts +3 -17
- package/dist/graph/build.js +49 -46
- package/dist/index.d.ts +3 -7
- package/dist/index.js +22 -62
- package/dist/plugins/angular/index.js +2 -3
- package/dist/plugins/bumpp/index.d.ts +8 -0
- package/dist/plugins/bumpp/index.js +11 -0
- package/dist/plugins/eslint/index.d.ts +7 -0
- package/dist/plugins/eslint/index.js +12 -0
- package/dist/plugins/glob/index.d.ts +0 -1
- package/dist/plugins/glob/index.js +0 -1
- package/dist/plugins/index.d.ts +24 -7
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/karma/helpers.js +1 -1
- package/dist/plugins/node-modules-inspector/index.d.ts +0 -1
- package/dist/plugins/node-modules-inspector/index.js +0 -1
- package/dist/plugins/nuxt/index.js +10 -3
- package/dist/plugins/nuxt/types.d.ts +3 -2
- package/dist/plugins/oxlint/index.d.ts +0 -1
- package/dist/plugins/oxlint/index.js +0 -1
- package/dist/plugins/playwright/index.d.ts +0 -1
- package/dist/plugins/playwright/index.js +0 -1
- package/dist/plugins/playwright-test/index.d.ts +0 -1
- package/dist/plugins/playwright-test/index.js +0 -1
- package/dist/plugins/pnpm/index.d.ts +8 -0
- package/dist/plugins/pnpm/index.js +12 -0
- package/dist/plugins/prisma/index.d.ts +0 -1
- package/dist/plugins/prisma/index.js +0 -1
- package/dist/plugins/rsbuild/index.js +23 -6
- package/dist/plugins/rsbuild/types.d.ts +3 -0
- package/dist/plugins/rslib/index.js +1 -1
- package/dist/plugins/rstest/index.d.ts +10 -0
- package/dist/plugins/rstest/index.js +29 -0
- package/dist/plugins/rstest/types.d.ts +6 -0
- package/dist/plugins/ts-node/index.d.ts +0 -1
- package/dist/plugins/ts-node/index.js +0 -1
- package/dist/plugins.js +3 -2
- package/dist/reporters/codeclimate.d.ts +1 -1
- package/dist/reporters/codeclimate.js +10 -10
- package/dist/reporters/codeowners.d.ts +1 -1
- package/dist/reporters/codeowners.js +5 -5
- package/dist/reporters/compact.d.ts +1 -1
- package/dist/reporters/compact.js +7 -7
- package/dist/reporters/disclosure.d.ts +1 -1
- package/dist/reporters/disclosure.js +2 -2
- package/dist/reporters/githubActions.d.ts +3 -0
- package/dist/reporters/githubActions.js +94 -0
- package/dist/reporters/index.d.ts +7 -6
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +4 -4
- package/dist/reporters/markdown.d.ts +1 -1
- package/dist/reporters/markdown.js +4 -4
- package/dist/reporters/symbols.js +1 -1
- package/dist/reporters/util/configuration-hints.d.ts +14 -2
- package/dist/reporters/util/configuration-hints.js +7 -7
- package/dist/reporters/util/util.d.ts +2 -2
- package/dist/reporters/util/util.js +4 -4
- package/dist/reporters/watch.d.ts +3 -4
- package/dist/reporters/watch.js +5 -5
- package/dist/schema/configuration.d.ts +176 -8
- package/dist/schema/plugins.d.ts +69 -0
- package/dist/schema/plugins.js +3 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +3 -0
- package/dist/types/args.d.ts +2 -0
- package/dist/types/config.d.ts +4 -10
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/imports.d.ts +1 -1
- package/dist/types/issues.d.ts +1 -2
- package/dist/types/module-graph.d.ts +5 -4
- package/dist/types/{cli.d.ts → options.d.ts} +2 -2
- package/dist/types/options.js +1 -0
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/project.d.ts +1 -7
- package/dist/typescript/SourceFile.d.ts +2 -2
- package/dist/typescript/ast-helpers.d.ts +4 -0
- package/dist/typescript/ast-helpers.js +29 -0
- package/dist/typescript/find-internal-references.js +10 -1
- package/dist/typescript/get-imports-and-exports.d.ts +2 -2
- package/dist/typescript/get-imports-and-exports.js +32 -23
- package/dist/typescript/visitors/dynamic-imports/importCall.js +6 -1
- package/dist/util/Performance.js +16 -6
- package/dist/util/cli-arguments.d.ts +3 -3
- package/dist/util/cli-arguments.js +4 -14
- package/dist/util/create-options.d.ts +1238 -0
- package/dist/util/create-options.js +112 -0
- package/dist/util/debug.js +3 -4
- package/dist/util/errors.d.ts +1 -1
- package/dist/util/file-entry-cache.js +3 -3
- package/dist/util/get-included-issue-types.d.ts +9 -13
- package/dist/util/get-included-issue-types.js +10 -16
- package/dist/util/get-referenced-inputs.js +1 -1
- package/dist/util/input.d.ts +1 -1
- package/dist/util/input.js +1 -1
- package/dist/util/is-identifier-referenced.d.ts +1 -1
- package/dist/util/is-identifier-referenced.js +2 -2
- package/dist/util/load-config.d.ts +2 -0
- package/dist/util/load-config.js +24 -0
- package/dist/util/modules.js +18 -7
- package/dist/util/path.d.ts +4 -4
- package/dist/util/path.js +5 -7
- package/dist/util/require.js +1 -2
- package/dist/util/tag.d.ts +1 -1
- package/dist/util/to-source-path.d.ts +1 -1
- package/dist/util/to-source-path.js +5 -5
- package/dist/util/trace.d.ts +6 -6
- package/dist/util/trace.js +18 -22
- package/dist/util/watch.d.ts +2 -5
- package/dist/util/watch.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/schema.json +12 -0
- package/dist/util/unwrap-function.d.ts +0 -1
- package/dist/util/unwrap-function.js +0 -13
- /package/dist/{types/cli.js → plugins/rstest/types.js} +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { toRelative } from '../util/path.js';
|
|
2
2
|
import { getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
|
|
3
|
-
const logIssueSet = (issues) => {
|
|
3
|
+
const logIssueSet = (issues, cwd) => {
|
|
4
4
|
for (const filePath of issues.sort())
|
|
5
|
-
console.log(toRelative(filePath));
|
|
5
|
+
console.log(toRelative(filePath, cwd));
|
|
6
6
|
};
|
|
7
|
-
const logIssueRecord = (issues) => {
|
|
7
|
+
const logIssueRecord = (issues, cwd) => {
|
|
8
8
|
const sortedByFilePath = issues.sort((a, b) => (a.filePath > b.filePath ? 1 : -1));
|
|
9
9
|
for (const issue of sortedByFilePath)
|
|
10
|
-
console.log(getIssueLine(issue));
|
|
10
|
+
console.log(getIssueLine(issue, cwd));
|
|
11
11
|
};
|
|
12
|
-
export default ({ report, issues, isShowProgress }) => {
|
|
12
|
+
export default ({ report, issues, isShowProgress, cwd }) => {
|
|
13
13
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
14
14
|
let totalIssues = 0;
|
|
15
15
|
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
@@ -27,10 +27,10 @@ export default ({ report, issues, isShowProgress }) => {
|
|
|
27
27
|
if (issuesForType.length > 0) {
|
|
28
28
|
title && console.log(getColoredTitle(title, issuesForType.length));
|
|
29
29
|
if (isSet) {
|
|
30
|
-
logIssueSet(Array.from(issues[reportType]));
|
|
30
|
+
logIssueSet(Array.from(issues[reportType]), cwd);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
logIssueRecord(issuesForType);
|
|
33
|
+
logIssueRecord(issuesForType, cwd);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
totalIssues = totalIssues + issuesForType.length;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getIssueTypeTitle, getTableForType } from './util/util.js';
|
|
2
|
-
export default ({ report, issues }) => {
|
|
2
|
+
export default ({ report, issues, cwd }) => {
|
|
3
3
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
4
4
|
for (let [reportType, isReportType] of Object.entries(report)) {
|
|
5
5
|
if (reportType === 'files')
|
|
@@ -9,7 +9,7 @@ export default ({ report, issues }) => {
|
|
|
9
9
|
const issuesForType = Object.values(issues[reportType]).flatMap(Object.values);
|
|
10
10
|
if (issuesForType.length > 0) {
|
|
11
11
|
console.log(`<details>\n${title ? `<summary>${title} (${issuesForType.length})</summary>\n` : ''}\n\`\`\``);
|
|
12
|
-
console.log(getTableForType(issuesForType, { isUseColors: false }).toString());
|
|
12
|
+
console.log(getTableForType(issuesForType, cwd, { isUseColors: false }).toString());
|
|
13
13
|
console.log('```\n\n</details>\n');
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ISSUE_TYPE_TITLE } from '../constants.js';
|
|
2
|
+
import { relative } from '../util/path.js';
|
|
3
|
+
import { hintPrinters } from './util/configuration-hints.js';
|
|
4
|
+
import { getIssueTypeTitle } from './util/util.js';
|
|
5
|
+
const createGitHubActionsLogger = () => {
|
|
6
|
+
const formatAnnotation = (level, message, options) => {
|
|
7
|
+
const params = [`file=${options.file}`];
|
|
8
|
+
if (options.startLine != null)
|
|
9
|
+
params.push(`line=${options.startLine}`);
|
|
10
|
+
if (options.endLine != null)
|
|
11
|
+
params.push(`endLine=${options.endLine}`);
|
|
12
|
+
if (options.startColumn != null)
|
|
13
|
+
params.push(`col=${options.startColumn}`);
|
|
14
|
+
if (options.endColumn != null)
|
|
15
|
+
params.push(`endColumn=${options.endColumn}`);
|
|
16
|
+
params.push(`title=✂️ Knip${options.title ? ` / ${options.title}` : ''}`);
|
|
17
|
+
const paramString = params.join(',');
|
|
18
|
+
console.log(`::${level} ${paramString}::${message}`);
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
info: (message) => console.log(message),
|
|
22
|
+
error: (message, options) => formatAnnotation('error', message, options),
|
|
23
|
+
warning: (message, options) => formatAnnotation('warning', message, options),
|
|
24
|
+
notice: (message, options) => formatAnnotation('notice', message, options),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default ({ report, issues, cwd, configurationHints, isDisableConfigHints, isTreatConfigHintsAsErrors, configFilePath, }) => {
|
|
28
|
+
const core = createGitHubActionsLogger();
|
|
29
|
+
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
30
|
+
for (let [reportType, isReportType] of Object.entries(report)) {
|
|
31
|
+
if (reportType === 'files')
|
|
32
|
+
reportType = '_files';
|
|
33
|
+
if (isReportType) {
|
|
34
|
+
const title = reportMultipleGroups && getIssueTypeTitle(reportType);
|
|
35
|
+
const issuesForType = Object.values(issues[reportType]).flatMap(Object.values);
|
|
36
|
+
if (issuesForType.length > 0) {
|
|
37
|
+
title && core.info(`${title} (${issuesForType.length})`);
|
|
38
|
+
for (const issue of issuesForType) {
|
|
39
|
+
if (issue.isFixed || issue.severity === 'off')
|
|
40
|
+
continue;
|
|
41
|
+
const log = issue.severity === 'error' ? core.error : core.warning;
|
|
42
|
+
const filePath = relative(cwd, issue.filePath);
|
|
43
|
+
const message = reportType === '_files' ? issue.symbol : `${issue.symbol} in ${filePath}`;
|
|
44
|
+
log(message, {
|
|
45
|
+
file: filePath,
|
|
46
|
+
startLine: issue.line ?? 1,
|
|
47
|
+
endLine: issue.line ?? 1,
|
|
48
|
+
startColumn: issue.col ?? 1,
|
|
49
|
+
endColumn: issue.col ?? 1,
|
|
50
|
+
title: ISSUE_TYPE_TITLE[issue.type],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!isDisableConfigHints && configurationHints.size > 0) {
|
|
57
|
+
const CONFIG_HINTS_TITLE = 'Configuration hints';
|
|
58
|
+
core.info(`${CONFIG_HINTS_TITLE} (${configurationHints.size})`);
|
|
59
|
+
for (const hint of configurationHints) {
|
|
60
|
+
const hintPrinter = hintPrinters.get(hint.type);
|
|
61
|
+
const message = hintPrinter?.print({
|
|
62
|
+
...hint,
|
|
63
|
+
filePath: hint.filePath ?? configFilePath ?? '',
|
|
64
|
+
configFilePath,
|
|
65
|
+
}) ?? '';
|
|
66
|
+
const file = hint.filePath
|
|
67
|
+
? relative(cwd, hint.filePath)
|
|
68
|
+
: configFilePath
|
|
69
|
+
? relative(cwd, configFilePath)
|
|
70
|
+
: 'knip.json';
|
|
71
|
+
const hintMessage = `${message}: ${hint.identifier} in ${file}`;
|
|
72
|
+
if (isTreatConfigHintsAsErrors) {
|
|
73
|
+
core.error(hintMessage, {
|
|
74
|
+
file,
|
|
75
|
+
startLine: 1,
|
|
76
|
+
endLine: 1,
|
|
77
|
+
startColumn: 1,
|
|
78
|
+
endColumn: 1,
|
|
79
|
+
title: CONFIG_HINTS_TITLE,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
core.notice(hintMessage, {
|
|
84
|
+
file,
|
|
85
|
+
startLine: 1,
|
|
86
|
+
endLine: 1,
|
|
87
|
+
startColumn: 1,
|
|
88
|
+
endColumn: 1,
|
|
89
|
+
title: CONFIG_HINTS_TITLE,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
symbols: (options: import("../index.js").ReporterOptions) => void;
|
|
3
|
-
compact: ({ report, issues, isShowProgress }: import("../index.js").ReporterOptions) => void;
|
|
4
|
-
codeowners: ({ report, issues, isShowProgress, options }: import("../index.js").ReporterOptions) => void;
|
|
5
|
-
disclosure: ({ report, issues }: import("../index.js").ReporterOptions) => void;
|
|
6
|
-
codeclimate: ({ report, issues }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
7
|
-
json: ({ report, issues, options }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
8
|
-
markdown: ({ report, issues }: import("../index.js").ReporterOptions) => void;
|
|
3
|
+
compact: ({ report, issues, isShowProgress, cwd }: import("../index.js").ReporterOptions) => void;
|
|
4
|
+
codeowners: ({ report, issues, isShowProgress, options, cwd }: import("../index.js").ReporterOptions) => void;
|
|
5
|
+
disclosure: ({ report, issues, cwd }: import("../index.js").ReporterOptions) => void;
|
|
6
|
+
codeclimate: ({ report, issues, cwd }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
7
|
+
json: ({ report, issues, options, cwd }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
8
|
+
markdown: ({ report, issues, cwd }: import("../index.js").ReporterOptions) => void;
|
|
9
|
+
'github-actions': ({ report, issues, cwd, configurationHints, isDisableConfigHints, isTreatConfigHintsAsErrors, configFilePath, }: import("../index.js").ReporterOptions) => void;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
package/dist/reporters/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import codeclimate from './codeclimate.js';
|
|
|
2
2
|
import codeowners from './codeowners.js';
|
|
3
3
|
import compact from './compact.js';
|
|
4
4
|
import disclosure from './disclosure.js';
|
|
5
|
+
import githubActions from './githubActions.js';
|
|
5
6
|
import json from './json.js';
|
|
6
7
|
import markdown from './markdown.js';
|
|
7
8
|
import symbols from './symbols.js';
|
|
@@ -13,4 +14,5 @@ export default {
|
|
|
13
14
|
codeclimate,
|
|
14
15
|
json,
|
|
15
16
|
markdown,
|
|
17
|
+
'github-actions': githubActions,
|
|
16
18
|
};
|
package/dist/reporters/json.d.ts
CHANGED
package/dist/reporters/json.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createOwnershipEngine } from '../util/codeowners.js';
|
|
|
2
2
|
import { isFile } from '../util/fs.js';
|
|
3
3
|
import { relative, resolve } from '../util/path.js';
|
|
4
4
|
import { convert } from './util/util.js';
|
|
5
|
-
export default async ({ report, issues, options }) => {
|
|
5
|
+
export default async ({ report, issues, options, cwd }) => {
|
|
6
6
|
let opts = {};
|
|
7
7
|
try {
|
|
8
8
|
opts = options ? JSON.parse(options) : opts;
|
|
@@ -15,7 +15,7 @@ export default async ({ report, issues, options }) => {
|
|
|
15
15
|
const findOwners = isFile(codeownersFilePath) && createOwnershipEngine(codeownersFilePath);
|
|
16
16
|
const flatten = (issues) => Object.values(issues).flatMap(Object.values);
|
|
17
17
|
const initRow = (filePath) => {
|
|
18
|
-
const file = relative(filePath);
|
|
18
|
+
const file = relative(cwd, filePath);
|
|
19
19
|
const row = {
|
|
20
20
|
file,
|
|
21
21
|
...(findOwners && { owners: findOwners(file).map(name => ({ name })) }),
|
|
@@ -54,7 +54,7 @@ export default async ({ report, issues, options }) => {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
if (
|
|
57
|
+
if (type === 'binaries') {
|
|
58
58
|
json[filePath][type]?.push({ name: symbol });
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
@@ -66,7 +66,7 @@ export default async ({ report, issues, options }) => {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
const output = JSON.stringify({
|
|
69
|
-
files: Array.from(issues.files).map(filePath => relative(filePath)),
|
|
69
|
+
files: Array.from(issues.files).map(filePath => relative(cwd, filePath)),
|
|
70
70
|
issues: Object.values(json),
|
|
71
71
|
});
|
|
72
72
|
process.stdout._handle?.setBlocking?.(true);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { relative, toRelative } from '../util/path.js';
|
|
2
2
|
import { getIssueTypeTitle } from './util/util.js';
|
|
3
|
-
export default ({ report, issues }) => {
|
|
3
|
+
export default ({ report, issues, cwd }) => {
|
|
4
4
|
console.log('# Knip report\n');
|
|
5
5
|
const getFilePath = (issue) => {
|
|
6
6
|
if (!(issue.line && issue.col))
|
|
7
|
-
return relative(issue.filePath);
|
|
8
|
-
return `${relative(issue.filePath)}:${issue.line}:${issue.col}`;
|
|
7
|
+
return relative(cwd, issue.filePath);
|
|
8
|
+
return `${relative(cwd, issue.filePath)}:${issue.line}:${issue.col}`;
|
|
9
9
|
};
|
|
10
10
|
const sortLongestSymbol = (a, b) => b.symbol.length - a.symbol.length;
|
|
11
11
|
const sortLongestFilePath = (a, b) => getFilePath(b).length - getFilePath(a).length;
|
|
@@ -20,7 +20,7 @@ export default ({ report, issues }) => {
|
|
|
20
20
|
console.log(`## ${title} (${issuesForType.length})\n`);
|
|
21
21
|
if (isSet) {
|
|
22
22
|
for (const issue of issuesForType.sort()) {
|
|
23
|
-
console.log(`* ${toRelative(issue)}`);
|
|
23
|
+
console.log(`* ${toRelative(issue, cwd)}`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
@@ -12,7 +12,7 @@ export default (options) => {
|
|
|
12
12
|
const issuesForType = Object.values(issues[reportType]).flatMap(Object.values);
|
|
13
13
|
if (issuesForType.length > 0) {
|
|
14
14
|
title && console.log(getColoredTitle(title, issuesForType.length));
|
|
15
|
-
console.log(getTableForType(issuesForType).toString());
|
|
15
|
+
console.log(getTableForType(issuesForType, options.cwd).toString());
|
|
16
16
|
totalIssues = totalIssues + issuesForType.length;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import type { ReporterOptions } from '../../types/issues.js';
|
|
2
|
-
|
|
1
|
+
import type { ConfigurationHintType, ReporterOptions } from '../../types/issues.js';
|
|
2
|
+
interface PrintHintOptions {
|
|
3
|
+
type: ConfigurationHintType;
|
|
4
|
+
identifier: string | RegExp;
|
|
5
|
+
filePath: string;
|
|
6
|
+
configFilePath?: string;
|
|
7
|
+
workspaceName?: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
}
|
|
10
|
+
declare const hintPrinters: Map<ConfigurationHintType, {
|
|
11
|
+
print: (options: PrintHintOptions) => string;
|
|
12
|
+
}>;
|
|
13
|
+
export { hintPrinters };
|
|
14
|
+
export declare const printConfigurationHints: ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }: ReporterOptions) => void;
|
|
@@ -14,7 +14,7 @@ const getTableForHints = (hints) => {
|
|
|
14
14
|
table.row();
|
|
15
15
|
table.cell('identifier', hint.identifier.toString());
|
|
16
16
|
table.cell('workspace', getWorkspaceName(hint));
|
|
17
|
-
table.cell('filePath', hint.filePath
|
|
17
|
+
table.cell('filePath', hint.filePath);
|
|
18
18
|
table.cell('description', dim(hint.message));
|
|
19
19
|
}
|
|
20
20
|
return table;
|
|
@@ -42,6 +42,7 @@ const hintPrinters = new Map([
|
|
|
42
42
|
['project-top-level', { print: topLevel }],
|
|
43
43
|
['package-entry', { print: packageEntry }],
|
|
44
44
|
]);
|
|
45
|
+
export { hintPrinters };
|
|
45
46
|
const hintTypesOrder = [
|
|
46
47
|
['workspace-unconfigured'],
|
|
47
48
|
['entry-top-level', 'project-top-level'],
|
|
@@ -52,10 +53,9 @@ const hintTypesOrder = [
|
|
|
52
53
|
['entry-empty', 'project-empty', 'entry-redundant', 'project-redundant'],
|
|
53
54
|
['package-entry'],
|
|
54
55
|
];
|
|
55
|
-
export const printConfigurationHints = ({ counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors,
|
|
56
|
+
export const printConfigurationHints = ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }) => {
|
|
56
57
|
if (counters.files > 20) {
|
|
57
|
-
const workspaces =
|
|
58
|
-
.map(workspace => workspace.dir)
|
|
58
|
+
const workspaces = includedWorkspaceDirs
|
|
59
59
|
.sort(byPathDepth)
|
|
60
60
|
.reverse()
|
|
61
61
|
.map(dir => ({ dir, size: 0 }));
|
|
@@ -66,7 +66,7 @@ export const printConfigurationHints = ({ counters, issues, tagHints, configurat
|
|
|
66
66
|
}
|
|
67
67
|
const hlWorkspaces = workspaces.sort((a, b) => b.size - a.size).filter(ws => ws.size > 1);
|
|
68
68
|
for (const { dir, size } of hlWorkspaces) {
|
|
69
|
-
const identifier = toRelative(dir) || '.';
|
|
69
|
+
const identifier = toRelative(dir, cwd) || '.';
|
|
70
70
|
configurationHints.add({ type: 'workspace-unconfigured', workspaceName: identifier, identifier, size });
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -81,7 +81,7 @@ export const printConfigurationHints = ({ counters, issues, tagHints, configurat
|
|
|
81
81
|
const rows = hintTypesOrder.flatMap(hintTypes => hintTypes.flatMap(hintType => {
|
|
82
82
|
const hints = hintsByType.get(hintType) ?? [];
|
|
83
83
|
return hints.map(hint => {
|
|
84
|
-
hint.filePath
|
|
84
|
+
hint.filePath = relative(cwd, hint.filePath ?? configFilePath ?? '');
|
|
85
85
|
const hintPrinter = hintPrinters.get(hint.type);
|
|
86
86
|
const message = hintPrinter ? hintPrinter.print({ ...hint, configFilePath }) : '';
|
|
87
87
|
return { ...hint, message };
|
|
@@ -93,7 +93,7 @@ export const printConfigurationHints = ({ counters, issues, tagHints, configurat
|
|
|
93
93
|
console.log(getColoredTitle('Tag issues', tagHints.size));
|
|
94
94
|
for (const hint of tagHints) {
|
|
95
95
|
const { filePath, identifier, tagName } = hint;
|
|
96
|
-
const message = `Unused tag in ${toRelative(filePath)}:`;
|
|
96
|
+
const message = `Unused tag in ${toRelative(filePath, cwd)}:`;
|
|
97
97
|
console.warn(dim(message), `${identifier} → ${tagName}`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -13,14 +13,14 @@ type LogIssueLine = {
|
|
|
13
13
|
parentSymbol?: string;
|
|
14
14
|
severity?: IssueSeverity;
|
|
15
15
|
};
|
|
16
|
-
export declare const getIssueLine: ({ owner, filePath, symbols, parentSymbol, severity }: LogIssueLine) => string;
|
|
16
|
+
export declare const getIssueLine: ({ owner, filePath, symbols, parentSymbol, severity }: LogIssueLine, cwd: string) => string;
|
|
17
17
|
export declare const convert: (issue: Issue | IssueSymbol) => {
|
|
18
18
|
name: string;
|
|
19
19
|
line: number | undefined;
|
|
20
20
|
col: number | undefined;
|
|
21
21
|
pos: number | undefined;
|
|
22
22
|
};
|
|
23
|
-
export declare const getTableForType: (issues: Issue[], options?: {
|
|
23
|
+
export declare const getTableForType: (issues: Issue[], cwd: string, options?: {
|
|
24
24
|
isUseColors?: boolean;
|
|
25
25
|
}) => Table;
|
|
26
26
|
export {};
|
|
@@ -10,11 +10,11 @@ const yellow = picocolors.yellow;
|
|
|
10
10
|
export const getIssueTypeTitle = (reportType) => ISSUE_TYPE_TITLE[reportType];
|
|
11
11
|
export const getColoredTitle = (title, count) => `${picocolors.yellowBright(picocolors.underline(title))} (${count})`;
|
|
12
12
|
export const getDimmedTitle = (title, count) => `${yellow(`${picocolors.underline(title)} (${count})`)}`;
|
|
13
|
-
export const getIssueLine = ({ owner, filePath, symbols, parentSymbol, severity }) => {
|
|
13
|
+
export const getIssueLine = ({ owner, filePath, symbols, parentSymbol, severity }, cwd) => {
|
|
14
14
|
const symbol = symbols ? `: ${symbols.map(s => s.symbol).join(', ')}` : '';
|
|
15
15
|
const parent = parentSymbol ? ` (${parentSymbol})` : '';
|
|
16
16
|
const print = severity === 'warn' ? dim : plain;
|
|
17
|
-
return `${owner ? `${picocolors.cyan(owner)} ` : ''}${print(`${relative(filePath)}${symbol}${parent}`)}`;
|
|
17
|
+
return `${owner ? `${picocolors.cyan(owner)} ` : ''}${print(`${relative(cwd, filePath)}${symbol}${parent}`)}`;
|
|
18
18
|
};
|
|
19
19
|
export const convert = (issue) => ({
|
|
20
20
|
name: issue.symbol,
|
|
@@ -39,7 +39,7 @@ const highlightSymbol = (issue) => (_) => {
|
|
|
39
39
|
}
|
|
40
40
|
return issue.symbol;
|
|
41
41
|
};
|
|
42
|
-
export const getTableForType = (issues, options = { isUseColors: true }) => {
|
|
42
|
+
export const getTableForType = (issues, cwd, options = { isUseColors: true }) => {
|
|
43
43
|
const table = new Table({ truncateStart: ['filePath'], noTruncate: ['symbolType'] });
|
|
44
44
|
for (const issue of issues.sort(sortByPos)) {
|
|
45
45
|
table.row();
|
|
@@ -49,7 +49,7 @@ export const getTableForType = (issues, options = { isUseColors: true }) => {
|
|
|
49
49
|
table.cell('parentSymbol', issue.parentSymbol && print(issue.parentSymbol));
|
|
50
50
|
table.cell('symbolType', issue.symbolType && issue.symbolType !== SymbolType.UNKNOWN && print(issue.symbolType));
|
|
51
51
|
const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
|
|
52
|
-
const cell = issue.type === 'files' ? '' : `${relative(issue.filePath)}${pos}`;
|
|
52
|
+
const cell = issue.type === 'files' ? '' : `${relative(cwd, issue.filePath)}${pos}`;
|
|
53
53
|
table.cell('filePath', print(cell));
|
|
54
54
|
table.cell('fixed', issue.isFixed && print('(removed)'));
|
|
55
55
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ConsoleStreamer } from '../ConsoleStreamer.js';
|
|
2
|
-
import type { Issues
|
|
2
|
+
import type { Issues } from '../types/issues.js';
|
|
3
|
+
import type { MainOptions } from '../util/create-options.js';
|
|
3
4
|
interface WatchReporter {
|
|
4
|
-
report: Report;
|
|
5
5
|
issues: Issues;
|
|
6
6
|
streamer: ConsoleStreamer;
|
|
7
7
|
startTime?: number;
|
|
8
8
|
size: number;
|
|
9
|
-
isDebug: boolean;
|
|
10
9
|
}
|
|
11
|
-
declare const _default: (
|
|
10
|
+
declare const _default: (options: MainOptions, { issues, streamer, startTime, size }: WatchReporter) => void;
|
|
12
11
|
export default _default;
|
package/dist/reporters/watch.js
CHANGED
|
@@ -2,11 +2,11 @@ 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 ({
|
|
6
|
-
const reportMultipleGroups = Object.values(
|
|
5
|
+
export default (options, { issues, streamer, startTime, size }) => {
|
|
6
|
+
const reportMultipleGroups = Object.values(options.includedIssueTypes).filter(Boolean).length > 1;
|
|
7
7
|
let totalIssues = 0;
|
|
8
8
|
const lines = [];
|
|
9
|
-
for (let [reportType, isReportType] of Object.entries(
|
|
9
|
+
for (let [reportType, isReportType] of Object.entries(options.includedIssueTypes)) {
|
|
10
10
|
if (reportType === 'files')
|
|
11
11
|
reportType = '_files';
|
|
12
12
|
if (isReportType) {
|
|
@@ -16,7 +16,7 @@ export default ({ report, issues, streamer, startTime, size, isDebug }) => {
|
|
|
16
16
|
if (title) {
|
|
17
17
|
lines.push(`${picocolors.yellowBright(picocolors.underline(title))} (${issuesForType.length})`);
|
|
18
18
|
}
|
|
19
|
-
lines.push(...getTableForType(issuesForType).toRows());
|
|
19
|
+
lines.push(...getTableForType(issuesForType, options.cwd).toRows());
|
|
20
20
|
}
|
|
21
21
|
totalIssues = totalIssues + issuesForType.length;
|
|
22
22
|
}
|
|
@@ -27,7 +27,7 @@ export default ({ report, issues, streamer, startTime, size, isDebug }) => {
|
|
|
27
27
|
const messages = totalIssues === 0
|
|
28
28
|
? ['✂️ Excellent, Knip found no issues.', '', picocolors.gray(summary)]
|
|
29
29
|
: [...lines, '', picocolors.gray(summary)];
|
|
30
|
-
if (isDebug)
|
|
30
|
+
if (options.isDebug)
|
|
31
31
|
console.log(messages.join('\n'));
|
|
32
32
|
else
|
|
33
33
|
streamer.cast(messages);
|