Skip to content

Commit 2eb9c6b

Browse files
committed
Cleanup and test
1 parent e536e39 commit 2eb9c6b

File tree

4 files changed

+53
-55
lines changed

4 files changed

+53
-55
lines changed

bun.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"knip-bun": "bin/knip-bun.js",
5151
},
5252
"dependencies": {
53+
"@actions/core": "^1.11.1",
5354
"@nodelib/fs.walk": "^1.2.3",
5455
"easy-table": "1.2.0",
5556
"enhanced-resolve": "^5.18.1",
@@ -87,6 +88,14 @@
8788
},
8889
},
8990
"packages": {
91+
"@actions/core": ["@actions/[email protected]", "", { "dependencies": { "@actions/exec": "^1.1.1", "@actions/http-client": "^2.0.1" } }, "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A=="],
92+
93+
"@actions/exec": ["@actions/[email protected]", "", { "dependencies": { "@actions/io": "^1.0.1" } }, "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w=="],
94+
95+
"@actions/http-client": ["@actions/[email protected]", "", { "dependencies": { "tunnel": "^0.0.6", "undici": "^5.25.4" } }, "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA=="],
96+
97+
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
98+
9099
"@astro-community/astro-embed-youtube": ["@astro-community/[email protected]", "", { "dependencies": { "lite-youtube-embed": "^0.3.3" }, "peerDependencies": { "astro": "^2.0.0 || ^3.0.0-beta || ^4.0.0-beta || ^5.0.0-beta" } }, "sha512-/mRfCl/eTBUz0kmjD1psOy0qoDDBorVp0QumUacjFcIkBullYtbeFQ2ZGZ+3N/tA6cR/OIyzr2QA4dQXlY6USg=="],
91100

92101
"@astrojs/check": ["@astrojs/[email protected]", "", { "dependencies": { "@astrojs/language-server": "^2.15.0", "chokidar": "^4.0.1", "kleur": "^4.1.5", "yargs": "^17.7.2" }, "peerDependencies": { "typescript": "^5.0.0" }, "bin": { "astro-check": "dist/bin.js" } }, "sha512-IOheHwCtpUfvogHHsvu0AbeRZEnjJg3MopdLddkJE70mULItS/Vh37BHcI00mcOJcH1vhD3odbpvWokpxam7xA=="],
@@ -219,6 +228,8 @@
219228

220229
"@expressive-code/plugin-text-markers": ["@expressive-code/[email protected]", "", { "dependencies": { "@expressive-code/core": "^0.41.1" } }, "sha512-PFvk91yY+H8KVEcyZSrktLoWzBgLVpowvMxOJooFn74roGxnU4TEBJpWcRnJFtMEwTLzWNnk10MSOApOccvSKg=="],
221230

231+
"@fastify/busboy": ["@fastify/[email protected]", "", {}, "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="],
232+
222233
"@iarna/toml": ["@iarna/[email protected]", "", {}, "sha512-td6ZUkz2oS3VeleBcN+m//Q6HlCFCPrnI0FZhrt/h4XqLEdOyYp2u21nd8MdsR+WJy5r9PTDaHTDDfhf4H4l6Q=="],
223234

224235
"@img/sharp-darwin-arm64": ["@img/[email protected]", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-arm64": "1.1.0" }, "os": "darwin", "cpu": "arm64" }, "sha512-pn44xgBtgpEbZsu+lWf2KNb6OAf70X68k+yk69Ic2Xz11zHR/w24/U49XT7AeRwJ0Px+mhALhU5LPci1Aymk7A=="],
@@ -1627,6 +1638,8 @@
16271638

16281639
"tslib": ["[email protected]", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
16291640

1641+
"tunnel": ["[email protected]", "", {}, "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="],
1642+
16301643
"type-fest": ["[email protected]", "", {}, "sha512-S/5/0kFftkq27FPNye0XM1e2NsnoD/3FS+pBmbjmmtLT6I+i344KoOf7pvXreaFsDamWeaJX55nczA1m5PsBDg=="],
16311644

16321645
"typedarray": ["[email protected]", "", {}, "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA=="],
@@ -1819,6 +1832,8 @@
18191832

18201833
"zwitch": ["[email protected]", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
18211834

1835+
"@actions/http-client/undici": ["[email protected]", "", { "dependencies": { "@fastify/busboy": "^2.0.0" } }, "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg=="],
1836+
18221837
"@astrojs/starlight/remark-directive": ["[email protected]", "", { "dependencies": { "@types/mdast": "^4.0.0", "mdast-util-directive": "^3.0.0", "micromark-extension-directive": "^3.0.0", "unified": "^11.0.0" } }, "sha512-gwglrEQEZcZYgVyG1tQuA+h58EZfq5CSULw7J90AFuCTyib1thgHPoqQ+h9iFvU6R+vnZ5oNFQR5QKgGpk741A=="],
18231838

18241839
"@expressive-code/plugin-shiki/shiki": ["[email protected]", "", { "dependencies": { "@shikijs/core": "3.2.2", "@shikijs/engine-javascript": "3.2.2", "@shikijs/engine-oniguruma": "3.2.2", "@shikijs/langs": "3.2.2", "@shikijs/themes": "3.2.2", "@shikijs/types": "3.2.2", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-0qWBkM2t/0NXPRcVgtLhtHv6Ak3Q5yI4K/ggMqcgLRKm4+pCs3namgZlhlat/7u2CuqNtlShNs9lENOG6n7UaQ=="],

packages/knip/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"schema-jsonc.json"
6161
],
6262
"dependencies": {
63+
"@actions/core": "^1.11.1",
6364
"@nodelib/fs.walk": "^1.2.3",
6465
"easy-table": "1.2.0",
6566
"enhanced-resolve": "^5.18.1",
Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,32 @@
11
import core from '@actions/core';
2+
import { ISSUE_TYPES, ISSUE_TYPE_TITLE } from 'src/constants.js';
23
import type { ReporterOptions } from '../types/issues.js';
34

4-
export const ISSUE_TYPES = [
5-
// must be _files
6-
'_files',
7-
'dependencies',
8-
'devDependencies',
9-
'optionalPeerDependencies',
10-
'unlisted',
11-
'binaries',
12-
'unresolved',
13-
'exports',
14-
'nsExports',
15-
'types',
16-
'nsTypes',
17-
'enumMembers',
18-
'classMembers',
19-
'duplicates',
20-
] as const;
21-
22-
const ISSUE_TYPE_TITLE = {
23-
files: 'Unused files',
24-
_files: 'Unused files',
25-
dependencies: 'Unused dependencies',
26-
devDependencies: 'Unused devDependencies',
27-
optionalPeerDependencies: 'Referenced optional peerDependencies',
28-
unlisted: 'Unlisted dependencies',
29-
binaries: 'Unlisted binaries',
30-
unresolved: 'Unresolved imports',
31-
exports: 'Unused exports',
32-
nsExports: 'Exports in used namespace',
33-
types: 'Unused exported types',
34-
nsTypes: 'Exported types in used namespace',
35-
enumMembers: 'Unused exported enum members',
36-
classMembers: 'Unused exported class members',
37-
duplicates: 'Duplicate exports',
38-
};
39-
40-
export default (options: ReporterOptions) => {
5+
export default ({ issues }: ReporterOptions) => {
416
for (const issueName of ISSUE_TYPES) {
42-
const issue = options.issues[issueName];
43-
44-
for (const file of Object.keys(issue)) {
45-
const issueSet = issue[file];
7+
const issue = issues[issueName];
468

47-
for (const issueKey of Object.keys(issueSet)) {
48-
const issueItem = issueSet[issueKey];
9+
const issueSet =
10+
issue instanceof Set ? Array.from(issue) : Object.values(issue).flatMap(record => Object.values(record));
4911

50-
if (issueItem.isFixed || issueItem.severity === 'off') {
51-
continue;
52-
}
12+
for (const issueItem of issueSet) {
13+
if (typeof issueItem === 'string') {
14+
core.info(issueItem);
15+
continue;
16+
}
17+
if (issueItem.isFixed || issueItem.severity === 'off') {
18+
continue;
19+
}
5320

54-
const log = issueItem.severity === 'error' ? core.error : core.warning;
21+
const log = issueItem.severity === 'error' ? core.error : core.warning;
5522

56-
log(ISSUE_TYPE_TITLE[issueItem.type], {
57-
file: file,
58-
startLine: issueItem.line,
59-
endLine: issueItem.line,
60-
endColumn: issueItem.col,
61-
startColumn: issueItem.col,
62-
});
63-
}
23+
log(ISSUE_TYPE_TITLE[issueItem.type], {
24+
file: issueItem.filePath,
25+
startLine: issueItem.line,
26+
endLine: issueItem.line,
27+
endColumn: issueItem.col,
28+
startColumn: issueItem.col,
29+
});
6430
}
6531
}
6632
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { resolve } from '../../src/util/path.js';
4+
import { exec } from '../helpers/exec.js';
5+
6+
const cwd = resolve('fixtures/module-resolution-non-std');
7+
8+
test('knip --reporter githubActions (files, unlisted & unresolved)', () => {
9+
assert.equal(
10+
exec('knip --reporter githubActions', { cwd }).stdout,
11+
`${cwd}/src/unused.ts
12+
::error file=${cwd}/src/index.ts::Unlisted dependencies
13+
::error file=${cwd}/src/index.ts::Unlisted dependencies
14+
::error file=${cwd}/src/index.ts,line=8,endLine=8,col=23,endColumn=23::Unresolved imports`
15+
);
16+
});

0 commit comments

Comments
 (0)