@aklinker1/check 1.0.2 → 1.0.5

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.
@@ -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
- return stdout.trim().split(/\r?\n/).filter((line) => !!line).map(
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/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@aklinker1/check",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/aklinker1/check"
7
+ },
8
+ "homepage": "https://github.com/aklinker1/check",
9
+ "author": {
10
+ "name": "Aaron Klinker",
11
+ "email": "aaronklinker1+npm@gmail.com"
12
+ },
13
+ "keywords": [
14
+ "lint",
15
+ "format",
16
+ "check",
17
+ "eslint",
18
+ "publint",
19
+ "prettier",
20
+ "typescript"
21
+ ],
4
22
  "type": "module",
5
23
  "exports": {
6
24
  ".": {