@aklinker1/check 1.0.1 → 1.0.3
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/tools/prettier.mjs +21 -2
- package/dist/tools/prettier.test.mjs +49 -0
- package/dist/utils.mjs +2 -0
- package/package.json +6 -1
package/dist/tools/prettier.mjs
CHANGED
|
@@ -8,8 +8,27 @@ export const prettier = {
|
|
|
8
8
|
check: (root) => execAndParse(root, bin, checkArgs, parseOuptut),
|
|
9
9
|
fix: (root) => execAndParse(root, bin, fixArgs, parseOuptut)
|
|
10
10
|
};
|
|
11
|
-
export const parseOuptut = ({ stdout }) => {
|
|
12
|
-
|
|
11
|
+
export const parseOuptut = ({ stdout, stderr }) => {
|
|
12
|
+
if (stderr.trim()) {
|
|
13
|
+
return stderr.split(/\r?\n/).reduce((acc, line) => {
|
|
14
|
+
const match = /^\[(.+?)\]\s?(.+?):\s?(.*?)\s?\(([0-9]+):([0-9])\)$/.exec(
|
|
15
|
+
line
|
|
16
|
+
);
|
|
17
|
+
if (match) {
|
|
18
|
+
acc.push({
|
|
19
|
+
file: match[2],
|
|
20
|
+
kind: match[1] === "error" ? "error" : "warning",
|
|
21
|
+
message: match[3],
|
|
22
|
+
location: {
|
|
23
|
+
line: parseInt(match[4], 10),
|
|
24
|
+
column: parseInt(match[5], 10)
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, []);
|
|
30
|
+
}
|
|
31
|
+
return stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map(
|
|
13
32
|
(line) => ({
|
|
14
33
|
file: line.trim(),
|
|
15
34
|
kind: "warning",
|
|
@@ -26,4 +26,53 @@ describe("Prettier", () => {
|
|
|
26
26
|
const code = 1;
|
|
27
27
|
expect(parseOuptut({ code, stdout, stderr })).toEqual([]);
|
|
28
28
|
});
|
|
29
|
+
it("should return an error when a syntax error is reported", async () => {
|
|
30
|
+
const stderr = `[error] src/components/CommitDiff.ts: SyntaxError: Declaration or statement expected. (15:1)
|
|
31
|
+
[error] 13 | });
|
|
32
|
+
[error] 14 |
|
|
33
|
+
[error] > 15 | }
|
|
34
|
+
[error] | ^
|
|
35
|
+
[error] 16 |
|
|
36
|
+
[error] src/components/CompareDiff.ts: Some other error message. (14:1)
|
|
37
|
+
[error] 12 | });
|
|
38
|
+
[error] 13 |
|
|
39
|
+
[error] > 14 | }
|
|
40
|
+
[error] | ^
|
|
41
|
+
[error] 15 |
|
|
42
|
+
`;
|
|
43
|
+
const stdout = `.github/assets/privacy-policy.md 18ms
|
|
44
|
+
.github/workflows/submit.yml 20ms
|
|
45
|
+
.github/workflows/validate.yml 4ms
|
|
46
|
+
.prettierrc.yml 0ms`;
|
|
47
|
+
const code = 1;
|
|
48
|
+
expect(parseOuptut({ code, stdout, stderr })).toEqual([
|
|
49
|
+
{
|
|
50
|
+
file: "src/components/CommitDiff.ts",
|
|
51
|
+
message: "SyntaxError: Declaration or statement expected.",
|
|
52
|
+
location: {
|
|
53
|
+
line: 15,
|
|
54
|
+
column: 1
|
|
55
|
+
},
|
|
56
|
+
kind: "error"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
file: "src/components/CompareDiff.ts",
|
|
60
|
+
message: "Some other error message.",
|
|
61
|
+
location: {
|
|
62
|
+
line: 14,
|
|
63
|
+
column: 1
|
|
64
|
+
},
|
|
65
|
+
kind: "error"
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
it("should not report warnings for fix output", () => {
|
|
70
|
+
const stderr = "";
|
|
71
|
+
const stdout = `.github/assets/privacy-policy.md 18ms
|
|
72
|
+
.github/workflows/submit.yml 20ms
|
|
73
|
+
.github/workflows/validate.yml 4ms
|
|
74
|
+
.prettierrc.yml 0ms`;
|
|
75
|
+
const code = 0;
|
|
76
|
+
expect(parseOuptut({ code, stdout, stderr })).toEqual([]);
|
|
77
|
+
});
|
|
29
78
|
});
|
package/dist/utils.mjs
CHANGED
|
@@ -38,6 +38,8 @@ export async function execAndParse(root, bin, args, parser) {
|
|
|
38
38
|
const res = await exec(resolveRoot(root, bin), args, { cwd: root });
|
|
39
39
|
if (res.exitCode == null)
|
|
40
40
|
throw Error("Exit code was null");
|
|
41
|
+
if (isDebug())
|
|
42
|
+
console.debug({ bin, args, root, ...res });
|
|
41
43
|
return parser({
|
|
42
44
|
code: res.exitCode,
|
|
43
45
|
stderr: res.stderr,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aklinker1/check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
],
|
|
40
40
|
"declaration": true
|
|
41
41
|
},
|
|
42
|
+
"changelog": {
|
|
43
|
+
"excludeAuthors": [
|
|
44
|
+
"aaronklinker1@gmail.com"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
42
47
|
"scripts": {
|
|
43
48
|
"build": "bunx --bun unbuild",
|
|
44
49
|
"check": "bun src/cli.ts",
|