knip 5.62.0 → 5.63.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.
- package/README.md +22 -24
- package/dist/CacheConsultant.d.ts +3 -9
- package/dist/CacheConsultant.js +5 -5
- package/dist/ConfigurationChief.d.ts +588 -38
- package/dist/ConfigurationChief.js +43 -124
- package/dist/ConsoleStreamer.d.ts +2 -3
- package/dist/ConsoleStreamer.js +2 -2
- package/dist/DependencyDeputy.d.ts +2 -6
- package/dist/IssueCollector.d.ts +4 -12
- package/dist/IssueCollector.js +10 -10
- package/dist/IssueFixer.d.ts +3 -14
- package/dist/IssueFixer.js +11 -21
- package/dist/PrincipalFactory.d.ts +3 -2
- package/dist/PrincipalFactory.js +11 -11
- package/dist/ProjectPrincipal.d.ts +5 -3
- package/dist/ProjectPrincipal.js +17 -11
- package/dist/WorkspaceWorker.d.ts +4 -9
- package/dist/WorkspaceWorker.js +8 -12
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/binaries/fallback.js +4 -2
- package/dist/binaries/package-manager/pnpm.js +6 -1
- package/dist/cli.js +43 -60
- package/dist/compilers/index.d.ts +34 -4
- package/dist/graph/analyze.d.ts +3 -8
- package/dist/graph/analyze.js +24 -27
- package/dist/graph/build.d.ts +3 -17
- package/dist/graph/build.js +60 -47
- package/dist/index.d.ts +3 -6
- package/dist/index.js +23 -62
- package/dist/plugins/astro/index.d.ts +1 -0
- package/dist/plugins/astro/index.js +4 -0
- package/dist/plugins/index.d.ts +24 -1
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/lefthook/index.js +2 -0
- package/dist/plugins/node-modules-inspector/index.d.ts +12 -0
- package/dist/plugins/node-modules-inspector/index.js +17 -0
- package/dist/plugins/nuxt/index.js +4 -3
- package/dist/plugins/nuxt/types.d.ts +3 -2
- package/dist/plugins/playwright/index.js +8 -1
- package/dist/plugins/playwright/types.d.ts +20 -14
- package/dist/plugins/pnpm/index.d.ts +7 -0
- package/dist/plugins/pnpm/index.js +8 -0
- package/dist/plugins/preconstruct/index.js +2 -1
- package/dist/plugins/react-router/index.js +18 -8
- package/dist/plugins/rsbuild/index.js +28 -2
- package/dist/plugins/rsbuild/types.d.ts +11 -0
- package/dist/plugins/rslib/index.d.ts +10 -0
- package/dist/plugins/rslib/index.js +15 -0
- package/dist/plugins/rslib/types.d.ts +1 -0
- package/dist/plugins/rspack/index.js +1 -1
- package/dist/plugins/typescript/index.d.ts +1 -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/index.d.ts +6 -6
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +3 -3
- package/dist/reporters/markdown.d.ts +1 -1
- package/dist/reporters/markdown.js +4 -4
- package/dist/reporters/symbols.js +4 -2
- package/dist/reporters/util/configuration-hints.d.ts +1 -1
- package/dist/reporters/util/configuration-hints.js +58 -23
- package/dist/reporters/util/util.d.ts +2 -4
- package/dist/reporters/util/util.js +6 -6
- 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/config.d.ts +4 -10
- package/dist/types/entries.d.ts +3 -0
- package/dist/types/entries.js +1 -0
- package/dist/types/issues.d.ts +4 -3
- 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 +5 -0
- package/dist/types/project.d.ts +1 -7
- package/dist/types/tsconfig-json.d.ts +14 -0
- package/dist/types/tsconfig-json.js +1 -0
- package/dist/typescript/ast-helpers.js +1 -1
- package/dist/typescript/get-imports-and-exports.d.ts +2 -2
- package/dist/typescript/get-imports-and-exports.js +9 -10
- package/dist/util/Performance.js +16 -6
- package/dist/util/cli-arguments.d.ts +1 -2
- package/dist/util/cli-arguments.js +3 -13
- package/dist/util/create-options.d.ts +1219 -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/fs.d.ts +1 -1
- 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/glob-core.d.ts +1 -1
- package/dist/util/glob-core.js +8 -7
- package/dist/util/glob.d.ts +1 -0
- package/dist/util/glob.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 +19 -19
- package/dist/util/load-config.d.ts +1 -0
- package/dist/util/load-config.js +24 -0
- package/dist/util/package-json.d.ts +2 -1
- package/dist/util/package-json.js +24 -12
- package/dist/util/parse-and-convert-gitignores.js +2 -0
- package/dist/util/path.d.ts +4 -4
- package/dist/util/path.js +5 -7
- package/dist/util/reporter.js +3 -3
- package/dist/util/require.js +1 -2
- package/dist/util/table.js +1 -3
- 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 +10 -15
- 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/rslib/types.js} +0 -0
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 })) }),
|
|
@@ -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
|
}
|
|
@@ -20,7 +20,9 @@ export default (options) => {
|
|
|
20
20
|
if (!isDisableConfigHints) {
|
|
21
21
|
printConfigurationHints(options);
|
|
22
22
|
}
|
|
23
|
-
if (totalIssues === 0 &&
|
|
23
|
+
if (totalIssues === 0 &&
|
|
24
|
+
isShowProgress &&
|
|
25
|
+
(!options.isTreatConfigHintsAsErrors || options.configurationHints.size === 0)) {
|
|
24
26
|
console.log('✂️ Excellent, Knip found no issues.');
|
|
25
27
|
}
|
|
26
28
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ReporterOptions } from '../../types/issues.js';
|
|
2
|
-
export declare const printConfigurationHints: ({ counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors,
|
|
2
|
+
export declare const printConfigurationHints: ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }: ReporterOptions) => void;
|
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
import { toRelative } from '../../util/path.js';
|
|
1
|
+
import { relative, toRelative } from '../../util/path.js';
|
|
2
|
+
import { Table } from '../../util/table.js';
|
|
2
3
|
import { byPathDepth } from '../../util/workspace.js';
|
|
3
|
-
import { bright, dim, getColoredTitle, getDimmedTitle
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
4
|
+
import { bright, dim, getColoredTitle, getDimmedTitle } from './util.js';
|
|
5
|
+
const getWorkspaceName = (hint) => hint.workspaceName &&
|
|
6
|
+
hint.workspaceName !== '.' &&
|
|
7
|
+
hint.type !== 'workspace-unconfigured' &&
|
|
8
|
+
hint.type !== 'package-entry'
|
|
9
|
+
? hint.workspaceName
|
|
10
|
+
: '';
|
|
11
|
+
const getTableForHints = (hints) => {
|
|
12
|
+
const table = new Table({ truncateStart: ['identifier', 'workspace', 'filePath'] });
|
|
13
|
+
for (const hint of hints) {
|
|
14
|
+
table.row();
|
|
15
|
+
table.cell('identifier', hint.identifier.toString());
|
|
16
|
+
table.cell('workspace', getWorkspaceName(hint));
|
|
17
|
+
table.cell('filePath', hint.filePath);
|
|
18
|
+
table.cell('description', dim(hint.message));
|
|
19
|
+
}
|
|
20
|
+
return table;
|
|
21
|
+
};
|
|
22
|
+
const type = (id) => bright(id.split('-').at(0));
|
|
23
|
+
const unused = (options) => `Remove from ${type(options.type)}`;
|
|
24
|
+
const empty = (options) => `Refine ${type(options.type)} pattern (no matches)`;
|
|
25
|
+
const remove = (options) => `Remove redundant ${type(options.type)} pattern`;
|
|
26
|
+
const topLevel = (options) => `Remove, or move unused top-level ${type(options.type)} to one of ${bright('"workspaces"')}`;
|
|
27
|
+
const add = (options) => options.configFilePath
|
|
28
|
+
? `Add ${bright('entry')} and/or refine ${bright('project')} files in ${bright(`workspaces["${options.workspaceName}"]`)} (${options.size} unused files)`
|
|
29
|
+
: `Create ${bright('knip.json')} configuration file with ${bright(`workspaces["${options.workspaceName}"]`)} object (${options.size} unused files)`;
|
|
30
|
+
const packageEntry = () => 'Package entry file not found';
|
|
12
31
|
const hintPrinters = new Map([
|
|
13
32
|
['ignoreBinaries', { print: unused }],
|
|
14
33
|
['ignoreDependencies', { print: unused }],
|
|
@@ -21,11 +40,21 @@ const hintPrinters = new Map([
|
|
|
21
40
|
['workspace-unconfigured', { print: add }],
|
|
22
41
|
['entry-top-level', { print: topLevel }],
|
|
23
42
|
['project-top-level', { print: topLevel }],
|
|
43
|
+
['package-entry', { print: packageEntry }],
|
|
24
44
|
]);
|
|
25
|
-
|
|
45
|
+
const hintTypesOrder = [
|
|
46
|
+
['workspace-unconfigured'],
|
|
47
|
+
['entry-top-level', 'project-top-level'],
|
|
48
|
+
['ignoreWorkspaces'],
|
|
49
|
+
['ignoreDependencies'],
|
|
50
|
+
['ignoreBinaries'],
|
|
51
|
+
['ignoreUnresolved'],
|
|
52
|
+
['entry-empty', 'project-empty', 'entry-redundant', 'project-redundant'],
|
|
53
|
+
['package-entry'],
|
|
54
|
+
];
|
|
55
|
+
export const printConfigurationHints = ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }) => {
|
|
26
56
|
if (counters.files > 20) {
|
|
27
|
-
const workspaces =
|
|
28
|
-
.map(workspace => workspace.dir)
|
|
57
|
+
const workspaces = includedWorkspaceDirs
|
|
29
58
|
.sort(byPathDepth)
|
|
30
59
|
.reverse()
|
|
31
60
|
.map(dir => ({ dir, size: 0 }));
|
|
@@ -36,28 +65,34 @@ export const printConfigurationHints = ({ counters, issues, tagHints, configurat
|
|
|
36
65
|
}
|
|
37
66
|
const hlWorkspaces = workspaces.sort((a, b) => b.size - a.size).filter(ws => ws.size > 1);
|
|
38
67
|
for (const { dir, size } of hlWorkspaces) {
|
|
39
|
-
const identifier = toRelative(dir) || '.';
|
|
68
|
+
const identifier = toRelative(dir, cwd) || '.';
|
|
40
69
|
configurationHints.add({ type: 'workspace-unconfigured', workspaceName: identifier, identifier, size });
|
|
41
70
|
}
|
|
42
71
|
}
|
|
43
72
|
if (configurationHints.size > 0) {
|
|
44
|
-
const isTopLevel = (type) => type.includes('top-level');
|
|
45
|
-
const hintOrderer = (a, b) => isTopLevel(a.type) && !isTopLevel(b.type) ? -1 : !isTopLevel(a.type) && isTopLevel(b.type) ? 1 : 0;
|
|
46
73
|
const getTitle = isTreatConfigHintsAsErrors ? getColoredTitle : getDimmedTitle;
|
|
47
|
-
const style = isTreatConfigHintsAsErrors ? plain : dim;
|
|
48
74
|
console.log(getTitle('Configuration hints', configurationHints.size));
|
|
49
|
-
const
|
|
50
|
-
for (const hint of
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
console.warn(style(hintPrinter.print({ ...hint, isRootOnly })));
|
|
75
|
+
const hintsByType = new Map();
|
|
76
|
+
for (const hint of configurationHints) {
|
|
77
|
+
const hints = hintsByType.get(hint.type) ?? [];
|
|
78
|
+
hintsByType.set(hint.type, [...hints, hint]);
|
|
54
79
|
}
|
|
80
|
+
const rows = hintTypesOrder.flatMap(hintTypes => hintTypes.flatMap(hintType => {
|
|
81
|
+
const hints = hintsByType.get(hintType) ?? [];
|
|
82
|
+
return hints.map(hint => {
|
|
83
|
+
hint.filePath = relative(cwd, hint.filePath ?? configFilePath ?? '');
|
|
84
|
+
const hintPrinter = hintPrinters.get(hint.type);
|
|
85
|
+
const message = hintPrinter ? hintPrinter.print({ ...hint, configFilePath }) : '';
|
|
86
|
+
return { ...hint, message };
|
|
87
|
+
});
|
|
88
|
+
}));
|
|
89
|
+
console.warn(getTableForHints(rows).toString());
|
|
55
90
|
}
|
|
56
91
|
if (tagHints.size > 0) {
|
|
57
92
|
console.log(getColoredTitle('Tag issues', tagHints.size));
|
|
58
93
|
for (const hint of tagHints) {
|
|
59
94
|
const { filePath, identifier, tagName } = hint;
|
|
60
|
-
const message = `Unused tag in ${toRelative(filePath)}:`;
|
|
95
|
+
const message = `Unused tag in ${toRelative(filePath, cwd)}:`;
|
|
61
96
|
console.warn(dim(message), `${identifier} → ${tagName}`);
|
|
62
97
|
}
|
|
63
98
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ISSUE_TYPE_TITLE } from '../../constants.js';
|
|
2
2
|
import { type Issue, type IssueSeverity, type IssueSymbol } from '../../types/issues.js';
|
|
3
3
|
import { Table } from '../../util/table.js';
|
|
4
|
-
export declare const plain: (text: string) => string;
|
|
5
4
|
export declare const dim: import("picocolors/types.js").Formatter;
|
|
6
5
|
export declare const bright: import("picocolors/types.js").Formatter;
|
|
7
|
-
export declare const yellow: import("picocolors/types.js").Formatter;
|
|
8
6
|
export declare const getIssueTypeTitle: (reportType: keyof typeof ISSUE_TYPE_TITLE) => string;
|
|
9
7
|
export declare const getColoredTitle: (title: string, count: number) => string;
|
|
10
8
|
export declare const getDimmedTitle: (title: string, count: number) => string;
|
|
@@ -15,14 +13,14 @@ type LogIssueLine = {
|
|
|
15
13
|
parentSymbol?: string;
|
|
16
14
|
severity?: IssueSeverity;
|
|
17
15
|
};
|
|
18
|
-
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;
|
|
19
17
|
export declare const convert: (issue: Issue | IssueSymbol) => {
|
|
20
18
|
name: string;
|
|
21
19
|
line: number | undefined;
|
|
22
20
|
col: number | undefined;
|
|
23
21
|
pos: number | undefined;
|
|
24
22
|
};
|
|
25
|
-
export declare const getTableForType: (issues: Issue[], options?: {
|
|
23
|
+
export declare const getTableForType: (issues: Issue[], cwd: string, options?: {
|
|
26
24
|
isUseColors?: boolean;
|
|
27
25
|
}) => Table;
|
|
28
26
|
export {};
|
|
@@ -3,18 +3,18 @@ import { ISSUE_TYPE_TITLE } from '../../constants.js';
|
|
|
3
3
|
import { SymbolType } from '../../types/issues.js';
|
|
4
4
|
import { relative } from '../../util/path.js';
|
|
5
5
|
import { Table } from '../../util/table.js';
|
|
6
|
-
|
|
6
|
+
const plain = (text) => text;
|
|
7
7
|
export const dim = picocolors.gray;
|
|
8
8
|
export const bright = picocolors.whiteBright;
|
|
9
|
-
|
|
9
|
+
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);
|