@aklinker1/check 2.3.0 → 2.4.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/README.md +1 -1
- package/dist/cli.js +3 -4
- package/dist/index.js +1 -1
- package/dist/{src-B6y5RIK9.js → src-BO05XkIX.js} +69 -35
- package/package.json +2 -6
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ pnpm check --fix
|
|
|
14
14
|
To enable checks for any of the following modules, just install them:
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
pnpm i -D typescript oxlint prettier publint eslint markdownlint-cli @typescript/native-preview
|
|
17
|
+
pnpm i -D typescript oxlint prettier publint eslint markdownlint-cli @typescript/native-preview cspell
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Contributing
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { i as ALL_TOOLS, t as check } from "./src-
|
|
2
|
-
import { isCI } from "ci-info";
|
|
1
|
+
import { a as isCi, i as ALL_TOOLS, t as check } from "./src-BO05XkIX.js";
|
|
3
2
|
|
|
4
3
|
//#region package.json
|
|
5
|
-
var version = "2.
|
|
4
|
+
var version = "2.4.0";
|
|
6
5
|
|
|
7
6
|
//#endregion
|
|
8
7
|
//#region src/cli.ts
|
|
@@ -28,7 +27,7 @@ if (boolArg("-h") || boolArg("--help")) {
|
|
|
28
27
|
process.exit(0);
|
|
29
28
|
}
|
|
30
29
|
await check({
|
|
31
|
-
fix: boolArg("-f") ?? boolArg("--fix") ?? !
|
|
30
|
+
fix: boolArg("-f") ?? boolArg("--fix") ?? !isCi,
|
|
32
31
|
debug: boolArg("-d") ?? boolArg("--debug") ?? false,
|
|
33
32
|
root: args.find((arg) => !arg.startsWith("-")) ?? "."
|
|
34
33
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { isCI } from "ci-info";
|
|
2
1
|
import { readFile } from "node:fs/promises";
|
|
3
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
4
3
|
import readline from "node:readline";
|
|
5
4
|
import { spawn } from "node:child_process";
|
|
6
5
|
|
|
7
6
|
//#region src/utils.ts
|
|
7
|
+
const env = process.env;
|
|
8
|
+
const isCi = Boolean(env.CI || env.JENKINS_URL);
|
|
9
|
+
const isDebug = env.DEBUG === "true" || env.DEBUG === "1";
|
|
8
10
|
function exec(cmd, opts) {
|
|
9
11
|
return new Promise((resolve$1, reject) => {
|
|
10
12
|
const child = spawn(cmd, {
|
|
@@ -31,12 +33,12 @@ function exec(cmd, opts) {
|
|
|
31
33
|
});
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
async function execAndParse(cmd, cwd, parser) {
|
|
35
|
-
const res = await exec(cmd, { cwd });
|
|
36
|
+
async function execAndParse(cmd, cwd$1, parser) {
|
|
37
|
+
const res = await exec(cmd, { cwd: cwd$1 });
|
|
36
38
|
if (res.exitCode == null) throw Error("Exit code was null");
|
|
37
|
-
if (isDebug
|
|
39
|
+
if (isDebug) console.debug({
|
|
38
40
|
cmd,
|
|
39
|
-
cwd,
|
|
41
|
+
cwd: cwd$1,
|
|
40
42
|
...res
|
|
41
43
|
});
|
|
42
44
|
return parser({
|
|
@@ -45,9 +47,6 @@ async function execAndParse(cmd, cwd, parser) {
|
|
|
45
47
|
stdout: res.stdout
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
function isDebug() {
|
|
49
|
-
return process.env.DEBUG === "true" || process.env.DEBUG === "1";
|
|
50
|
-
}
|
|
51
50
|
const bold = (str) => `\x1b[1m${str}\x1b[0m`;
|
|
52
51
|
const dim = (str) => `\x1b[2m${str}\x1b[0m`;
|
|
53
52
|
const red = (str) => `\x1b[31m${str}\x1b[0m`;
|
|
@@ -60,7 +59,7 @@ function humanMs(ms) {
|
|
|
60
59
|
return `${minutes > 0 ? `${minutes}m ` : ""}${seconds}s`;
|
|
61
60
|
}
|
|
62
61
|
function debug(message) {
|
|
63
|
-
if (isDebug
|
|
62
|
+
if (isDebug) console.debug(dim("⚙ " + message));
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
//#endregion
|
|
@@ -145,6 +144,34 @@ const SPINNER_FRAMES = {
|
|
|
145
144
|
error: [red("✗")]
|
|
146
145
|
};
|
|
147
146
|
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/tools/cspell.ts
|
|
149
|
+
const cspell = ({ root }) => {
|
|
150
|
+
const checkCmd = "cspell --no-progress --no-summary .";
|
|
151
|
+
return {
|
|
152
|
+
name: "CSpell",
|
|
153
|
+
packageName: "cspell",
|
|
154
|
+
check: () => execAndParse(checkCmd, root, parseOutput$7)
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const NEWLINE_REGEX$6 = /\r?\n/;
|
|
158
|
+
const ERROR_REGEX$3 = /^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+)\s+-\s+(?<message>.*)$/;
|
|
159
|
+
const parseOutput$7 = ({ stdout }) => {
|
|
160
|
+
return stdout.split(NEWLINE_REGEX$6).reduce((acc, line) => {
|
|
161
|
+
const groups = ERROR_REGEX$3.exec(line)?.groups;
|
|
162
|
+
if (groups) acc.push({
|
|
163
|
+
file: groups.file,
|
|
164
|
+
kind: "error",
|
|
165
|
+
message: groups.message,
|
|
166
|
+
location: {
|
|
167
|
+
line: parseInt(groups.line, 10),
|
|
168
|
+
column: parseInt(groups.column, 10)
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return acc;
|
|
172
|
+
}, []);
|
|
173
|
+
};
|
|
174
|
+
|
|
148
175
|
//#endregion
|
|
149
176
|
//#region src/tools/eslint.ts
|
|
150
177
|
const eslint = ({ root }) => {
|
|
@@ -157,9 +184,11 @@ const eslint = ({ root }) => {
|
|
|
157
184
|
fix: () => execAndParse(fixCmd, root, parseOutput$6)
|
|
158
185
|
};
|
|
159
186
|
};
|
|
187
|
+
const NEWLINE_REGEX$5 = /\r?\n/;
|
|
188
|
+
const LINT_REGEX$1 = /^(?<file>.*?): line (?<line>[0-9]+), col (?<column>[0-9]+), (?<kind>\S+) - (?<message>.*?) \((?<rule>\S*?)\)$/;
|
|
160
189
|
const parseOutput$6 = ({ stdout, stderr }) => {
|
|
161
|
-
return `${stdout}\n${stderr}`.split(
|
|
162
|
-
const groups =
|
|
190
|
+
return `${stdout}\n${stderr}`.split(NEWLINE_REGEX$5).reduce((acc, line) => {
|
|
191
|
+
const groups = LINT_REGEX$1.exec(line)?.groups;
|
|
163
192
|
if (groups) acc.push({
|
|
164
193
|
file: groups.file,
|
|
165
194
|
kind: groups.kind === "Warning" ? "warning" : "error",
|
|
@@ -213,7 +242,7 @@ const oxfmt = ({ root }) => {
|
|
|
213
242
|
fix: () => execAndParse(fixCmd, root, parseOutput$4)
|
|
214
243
|
};
|
|
215
244
|
};
|
|
216
|
-
const NEWLINE_REGEX = /\r?\n/;
|
|
245
|
+
const NEWLINE_REGEX$4 = /\r?\n/;
|
|
217
246
|
const SYNTAX_ERROR_REGEX = /^\s*?[×✕]\s+(?<message>.+?)\r?\n\s+╭─\[(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+)\]/;
|
|
218
247
|
const parseOutput$4 = ({ stdout, stderr }) => {
|
|
219
248
|
const problems = [];
|
|
@@ -226,7 +255,7 @@ const parseOutput$4 = ({ stdout, stderr }) => {
|
|
|
226
255
|
column: parseInt(groups.column, 10)
|
|
227
256
|
}
|
|
228
257
|
});
|
|
229
|
-
for (const line of stdout.trim().split(NEWLINE_REGEX)) {
|
|
258
|
+
for (const line of stdout.trim().split(NEWLINE_REGEX$4)) {
|
|
230
259
|
if (!line || line.includes(" ")) continue;
|
|
231
260
|
problems.push({
|
|
232
261
|
file: line.trim(),
|
|
@@ -249,9 +278,11 @@ const oxlint = ({ root }) => {
|
|
|
249
278
|
fix: () => execAndParse(fixCmd, root, parseOutput$3)
|
|
250
279
|
};
|
|
251
280
|
};
|
|
281
|
+
const NEWLINE_REGEX$3 = /\r?\n/;
|
|
282
|
+
const LINT_REGEX = /^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+):\s?(?<message>.*?)\s?\[(?<kind>Warning|Error)\/?(?<rule>.*?)\]\s?$/;
|
|
252
283
|
const parseOutput$3 = ({ stdout }) => {
|
|
253
|
-
|
|
254
|
-
const groups =
|
|
284
|
+
return stdout.split(NEWLINE_REGEX$3).reduce((acc, line) => {
|
|
285
|
+
const groups = LINT_REGEX.exec(line)?.groups;
|
|
255
286
|
if (groups) acc.push({
|
|
256
287
|
file: groups.file,
|
|
257
288
|
kind: groups.kind === "Error" ? "error" : "warning",
|
|
@@ -264,11 +295,6 @@ const parseOutput$3 = ({ stdout }) => {
|
|
|
264
295
|
});
|
|
265
296
|
return acc;
|
|
266
297
|
}, []);
|
|
267
|
-
return stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map((line) => ({
|
|
268
|
-
file: line.trim(),
|
|
269
|
-
kind: "warning",
|
|
270
|
-
message: "Not formatted."
|
|
271
|
-
}));
|
|
272
298
|
};
|
|
273
299
|
|
|
274
300
|
//#endregion
|
|
@@ -283,9 +309,11 @@ const prettier = ({ root }) => {
|
|
|
283
309
|
fix: () => execAndParse(fixCmd, root, parseOutput$2)
|
|
284
310
|
};
|
|
285
311
|
};
|
|
312
|
+
const NEWLINE_REGEX$2 = /\r?\n/;
|
|
313
|
+
const ERROR_REGEX$2 = /^\[(?<kind>.+?)\]\s?(?<file>.+?):\s?(?<message>.*?)\s?\((?<line>[0-9]+):(?<column>[0-9]+)\)$/;
|
|
286
314
|
const parseOutput$2 = ({ stdout, stderr }) => {
|
|
287
|
-
if (stderr.trim()) return stderr.split(
|
|
288
|
-
const groups =
|
|
315
|
+
if (stderr.trim()) return stderr.split(NEWLINE_REGEX$2).reduce((acc, line) => {
|
|
316
|
+
const groups = ERROR_REGEX$2.exec(line)?.groups;
|
|
289
317
|
if (groups) acc.push({
|
|
290
318
|
file: groups.file,
|
|
291
319
|
kind: groups.kind === "error" ? "error" : "warning",
|
|
@@ -297,7 +325,7 @@ const parseOutput$2 = ({ stdout, stderr }) => {
|
|
|
297
325
|
});
|
|
298
326
|
return acc;
|
|
299
327
|
}, []);
|
|
300
|
-
return stdout.trim().split(
|
|
328
|
+
return stdout.trim().split(NEWLINE_REGEX$2).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map((line) => ({
|
|
301
329
|
file: line.trim(),
|
|
302
330
|
kind: "warning",
|
|
303
331
|
message: "Not formatted."
|
|
@@ -314,14 +342,16 @@ const publint = ({ root }) => {
|
|
|
314
342
|
check: () => execAndParse(cmd, root, parseOutput$1)
|
|
315
343
|
};
|
|
316
344
|
};
|
|
345
|
+
const NEWLINE_REGEX$1 = /\r?\n/;
|
|
346
|
+
const ERROR_REGEX$1 = /^[0-9]+\.\s?(?<message>.*)$/;
|
|
317
347
|
const parseOutput$1 = ({ stdout }) => {
|
|
318
348
|
let kind = "warning";
|
|
319
|
-
return stdout.split(
|
|
349
|
+
return stdout.split(NEWLINE_REGEX$1).reduce((acc, line) => {
|
|
320
350
|
if (line.includes("Errors:")) {
|
|
321
351
|
kind = "error";
|
|
322
352
|
return acc;
|
|
323
353
|
}
|
|
324
|
-
const groups =
|
|
354
|
+
const groups = ERROR_REGEX$1.exec(line)?.groups;
|
|
325
355
|
if (groups == null) return acc;
|
|
326
356
|
acc.push({
|
|
327
357
|
kind,
|
|
@@ -361,9 +391,11 @@ const typescript = async ({ root, packageJson }) => {
|
|
|
361
391
|
check: async () => execAndParse(mod.cmd, root, parseOutput)
|
|
362
392
|
};
|
|
363
393
|
};
|
|
394
|
+
const NEWLINE_REGEX = /\r?\n/;
|
|
395
|
+
const ERROR_REGEX = /^(?<file>\S+?)\((?<line>[0-9]+),(?<column>[0-9]+)\): \w+? (?<rule>TS[0-9]+): (?<message>.*)$/;
|
|
364
396
|
const parseOutput = ({ stdout }) => {
|
|
365
|
-
return stdout.split(
|
|
366
|
-
const groups =
|
|
397
|
+
return stdout.split(NEWLINE_REGEX).reduce((acc, line) => {
|
|
398
|
+
const groups = ERROR_REGEX.exec(line)?.groups;
|
|
367
399
|
if (groups) acc.push({
|
|
368
400
|
file: groups.file,
|
|
369
401
|
kind: "error",
|
|
@@ -381,9 +413,10 @@ const parseOutput = ({ stdout }) => {
|
|
|
381
413
|
//#endregion
|
|
382
414
|
//#region src/tools/index.ts
|
|
383
415
|
const ALL_TOOLS = [
|
|
384
|
-
|
|
416
|
+
cspell,
|
|
385
417
|
eslint,
|
|
386
418
|
markdownlint,
|
|
419
|
+
oxfmt,
|
|
387
420
|
oxlint,
|
|
388
421
|
prettier,
|
|
389
422
|
publint,
|
|
@@ -392,8 +425,9 @@ const ALL_TOOLS = [
|
|
|
392
425
|
|
|
393
426
|
//#endregion
|
|
394
427
|
//#region src/index.ts
|
|
428
|
+
const cwd = process.cwd();
|
|
395
429
|
async function check(options = {}) {
|
|
396
|
-
const { debug: debug$1, fix = !
|
|
430
|
+
const { debug: debug$1, fix = !isCi, root = cwd } = options;
|
|
397
431
|
const packageJson = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
398
432
|
if (debug$1) process.env.DEBUG = "true";
|
|
399
433
|
console.log();
|
|
@@ -409,7 +443,7 @@ async function check(options = {}) {
|
|
|
409
443
|
packageJson
|
|
410
444
|
});
|
|
411
445
|
if (tools.length === 0) {
|
|
412
|
-
if (isDebug
|
|
446
|
+
if (isDebug) console.log("No tools detected!");
|
|
413
447
|
else console.log("No tools detected! Run with --debug for more info");
|
|
414
448
|
console.log();
|
|
415
449
|
process.exit(1);
|
|
@@ -418,7 +452,7 @@ async function check(options = {}) {
|
|
|
418
452
|
const startTime = performance.now();
|
|
419
453
|
const problems$1 = await (fix ? tool.fix ?? tool.check : tool.check)();
|
|
420
454
|
problems$1.forEach((problem) => {
|
|
421
|
-
problem.file = resolve(root
|
|
455
|
+
problem.file = resolve(root, problem.file);
|
|
422
456
|
});
|
|
423
457
|
const duration = humanMs(performance.now() - startTime);
|
|
424
458
|
const title = `${tool.name} ${dim(`(${duration})`)}`;
|
|
@@ -446,7 +480,7 @@ async function check(options = {}) {
|
|
|
446
480
|
}, /* @__PURE__ */ new Map());
|
|
447
481
|
console.log([...groupedProblems.values()].map(renderProblemGroup).join("\n"));
|
|
448
482
|
const files = Object.entries(problems.reduce((acc, problem) => {
|
|
449
|
-
const file = "." + sep + relative(
|
|
483
|
+
const file = "." + sep + relative(root, problem.file);
|
|
450
484
|
acc[file] ??= 0;
|
|
451
485
|
acc[file]++;
|
|
452
486
|
return acc;
|
|
@@ -468,7 +502,7 @@ async function findInstalledTools(opts) {
|
|
|
468
502
|
isInstalled: !!opts.packageJson.devDependencies?.[tool.packageName]
|
|
469
503
|
};
|
|
470
504
|
}));
|
|
471
|
-
if (isDebug
|
|
505
|
+
if (isDebug) {
|
|
472
506
|
const getTools = (isInstalled) => status.filter((item) => item.isInstalled === isInstalled).map((item) => item.tool.name).join(", ");
|
|
473
507
|
debug(`Installed: ${getTools(true) || "(none)"}`);
|
|
474
508
|
debug(`Skipping: ${getTools(false) || "(none)"} `);
|
|
@@ -481,7 +515,7 @@ function plural(count, singular, plural$1) {
|
|
|
481
515
|
function renderProblemGroup(problems) {
|
|
482
516
|
const renderedProblems = problems.map(renderProblem);
|
|
483
517
|
const problem = problems[0];
|
|
484
|
-
const path = relative(
|
|
518
|
+
const path = relative(cwd, problem.file);
|
|
485
519
|
const link = dim(`→ .${sep}${problem.location ? `${path}:${problem.location.line}:${problem.location.column}` : path}`);
|
|
486
520
|
return `${renderedProblems.join("\n")}\n ${link}`;
|
|
487
521
|
}
|
|
@@ -492,4 +526,4 @@ function renderProblem(problem) {
|
|
|
492
526
|
}
|
|
493
527
|
|
|
494
528
|
//#endregion
|
|
495
|
-
export { ALL_TOOLS as i, renderProblem as n, renderProblemGroup as r, check as t };
|
|
529
|
+
export { isCi as a, ALL_TOOLS as i, renderProblem as n, renderProblemGroup as r, check as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aklinker1/check",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"check",
|
|
6
6
|
"eslint",
|
|
@@ -39,11 +39,7 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsdown src/index.ts src/cli.ts",
|
|
41
41
|
"check": "bun src/cli.ts",
|
|
42
|
-
"prepack": "bun run build"
|
|
43
|
-
"prepublish": "bun run build"
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"ci-info": "*"
|
|
42
|
+
"prepack": "bun run build"
|
|
47
43
|
},
|
|
48
44
|
"devDependencies": {
|
|
49
45
|
"@types/bun": "latest",
|