@robhowley/pi-structured-return 1.4.0 → 1.6.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.
Files changed (72) hide show
  1. package/README.md +108 -74
  2. package/extensions/structured-return/src/config/registry.test.ts +171 -0
  3. package/extensions/structured-return/src/config/registry.ts +183 -14
  4. package/extensions/structured-return/src/index.test.ts +54 -0
  5. package/extensions/structured-return/src/index.ts +20 -9
  6. package/extensions/structured-return/src/parsers/ava-text.test.ts +116 -0
  7. package/extensions/structured-return/src/parsers/ava-text.ts +161 -0
  8. package/extensions/structured-return/src/parsers/bandit-json.test.ts +90 -0
  9. package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
  10. package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
  11. package/extensions/structured-return/src/parsers/black-text.ts +74 -0
  12. package/extensions/structured-return/src/parsers/cargo-build.ts +2 -2
  13. package/extensions/structured-return/src/parsers/cargo-test.ts +2 -2
  14. package/extensions/structured-return/src/parsers/clang-text.test.ts +61 -0
  15. package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
  16. package/extensions/structured-return/src/parsers/dbt-json.ts +2 -2
  17. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
  18. package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
  19. package/extensions/structured-return/src/parsers/eslint-json.ts +2 -2
  20. package/extensions/structured-return/src/parsers/go-test-json.test.ts +119 -0
  21. package/extensions/structured-return/src/parsers/go-test-json.ts +137 -0
  22. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +73 -0
  23. package/extensions/structured-return/src/parsers/hadolint-json.ts +55 -0
  24. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +72 -0
  25. package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
  26. package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
  27. package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
  28. package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
  29. package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
  30. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
  31. package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
  32. package/extensions/structured-return/src/parsers/junit-xml.ts +2 -2
  33. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
  34. package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
  35. package/extensions/structured-return/src/parsers/minitest-text.ts +2 -2
  36. package/extensions/structured-return/src/parsers/mocha-json.test.ts +108 -0
  37. package/extensions/structured-return/src/parsers/mocha-json.ts +77 -0
  38. package/extensions/structured-return/src/parsers/mypy-json.test.ts +101 -0
  39. package/extensions/structured-return/src/parsers/mypy-json.ts +80 -0
  40. package/extensions/structured-return/src/parsers/node-test-text.test.ts +117 -0
  41. package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
  42. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
  43. package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
  44. package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
  45. package/extensions/structured-return/src/parsers/prettier-text.ts +63 -0
  46. package/extensions/structured-return/src/parsers/pylint-json.test.ts +120 -0
  47. package/extensions/structured-return/src/parsers/pylint-json.ts +64 -0
  48. package/extensions/structured-return/src/parsers/pyright-json.test.ts +112 -0
  49. package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
  50. package/extensions/structured-return/src/parsers/rspec-json.ts +2 -2
  51. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +118 -0
  52. package/extensions/structured-return/src/parsers/rubocop-json.ts +65 -0
  53. package/extensions/structured-return/src/parsers/ruff-json.ts +2 -2
  54. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +110 -0
  55. package/extensions/structured-return/src/parsers/shellcheck-json.ts +61 -0
  56. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +120 -0
  57. package/extensions/structured-return/src/parsers/stylelint-json.ts +68 -0
  58. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +73 -0
  59. package/extensions/structured-return/src/parsers/swiftc-text.ts +47 -0
  60. package/extensions/structured-return/src/parsers/tail-fallback.ts +2 -2
  61. package/extensions/structured-return/src/parsers/tidy-text.test.ts +74 -0
  62. package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
  63. package/extensions/structured-return/src/parsers/tsc-text.test.ts +81 -0
  64. package/extensions/structured-return/src/parsers/tsc-text.ts +47 -0
  65. package/extensions/structured-return/src/parsers/unittest-text.test.ts +126 -0
  66. package/extensions/structured-return/src/parsers/unittest-text.ts +116 -0
  67. package/extensions/structured-return/src/parsers/utils.ts +43 -0
  68. package/extensions/structured-return/src/parsers/vale-json.test.ts +84 -0
  69. package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
  70. package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
  71. package/package.json +1 -1
  72. package/skills/structured-return/SKILL.md +93 -2
@@ -0,0 +1,112 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./pyright-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pyright-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "pyright --outputjson .",
14
+ argv: ["pyright", "--outputjson", "."],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("pyright-json parser", () => {
24
+ it("single error → correct relative path, 1-based line, rule mapped, status fail", async () => {
25
+ const cwd = "/project";
26
+ const stdout = JSON.stringify({
27
+ version: "1.1.408",
28
+ generalDiagnostics: [
29
+ {
30
+ file: "/project/src/app.py",
31
+ severity: "error",
32
+ message: 'Type "str" is not assignable to declared type "int"\n "str" is not assignable to "int"',
33
+ range: { start: { line: 3, character: 14 }, end: { line: 3, character: 28 } },
34
+ rule: "reportAssignmentType",
35
+ },
36
+ ],
37
+ summary: { filesAnalyzed: 1, errorCount: 1, warningCount: 0, informationCount: 0 },
38
+ });
39
+ const result = await parser.parse(makeCtx(stdout, cwd));
40
+ expect(result.status).toBe("fail");
41
+ expect(result.summary).toBe("1 error");
42
+ expect(result.failures).toHaveLength(1);
43
+ expect(result.failures![0].file).toBe("src/app.py");
44
+ expect(result.failures![0].line).toBe(4); // 0-based → 1-based
45
+ expect(result.failures![0].rule).toBe("reportAssignmentType");
46
+ expect(result.failures![0].message).not.toContain("\n");
47
+ });
48
+
49
+ it("multiple errors across files → correct count and paths", async () => {
50
+ const cwd = "/project";
51
+ const stdout = JSON.stringify({
52
+ generalDiagnostics: [
53
+ {
54
+ file: "/project/a.py",
55
+ severity: "error",
56
+ message: 'Cannot access attribute "foo" for class "Bar"',
57
+ range: { start: { line: 0, character: 0 }, end: { line: 0, character: 5 } },
58
+ rule: "reportAttributeAccessIssue",
59
+ },
60
+ {
61
+ file: "/project/b.py",
62
+ severity: "error",
63
+ message: 'Argument missing for parameter "x"',
64
+ range: { start: { line: 9, character: 0 }, end: { line: 9, character: 10 } },
65
+ rule: "reportCallIssue",
66
+ },
67
+ ],
68
+ summary: { filesAnalyzed: 2, errorCount: 2, warningCount: 0, informationCount: 0 },
69
+ });
70
+ const result = await parser.parse(makeCtx(stdout, cwd));
71
+ expect(result.status).toBe("fail");
72
+ expect(result.summary).toBe("2 errors");
73
+ expect(result.failures).toHaveLength(2);
74
+ expect(result.failures![0].file).toBe("a.py");
75
+ expect(result.failures![1].file).toBe("b.py");
76
+ });
77
+
78
+ it("warnings only (no errors) → status pass, empty failures", async () => {
79
+ const stdout = JSON.stringify({
80
+ generalDiagnostics: [
81
+ {
82
+ file: "/project/c.py",
83
+ severity: "warning",
84
+ message: 'Import "os" is not accessed',
85
+ range: { start: { line: 0, character: 0 }, end: { line: 0, character: 9 } },
86
+ rule: "reportUnusedImport",
87
+ },
88
+ ],
89
+ summary: { filesAnalyzed: 1, errorCount: 0, warningCount: 1, informationCount: 0 },
90
+ });
91
+ const result = await parser.parse(makeCtx(stdout));
92
+ expect(result.status).toBe("pass");
93
+ expect(result.summary).toBe("1 warning");
94
+ expect(result.failures).toHaveLength(0);
95
+ });
96
+
97
+ it("no diagnostics → status pass", async () => {
98
+ const stdout = JSON.stringify({
99
+ generalDiagnostics: [],
100
+ summary: { filesAnalyzed: 1, errorCount: 0, warningCount: 0, informationCount: 0 },
101
+ });
102
+ const result = await parser.parse(makeCtx(stdout));
103
+ expect(result.status).toBe("pass");
104
+ expect(result.failures).toHaveLength(0);
105
+ });
106
+
107
+ it("empty stdout → no crash, status pass", async () => {
108
+ const result = await parser.parse(makeCtx(""));
109
+ expect(result.status).toBe("pass");
110
+ expect(result.failures).toHaveLength(0);
111
+ });
112
+ });
@@ -0,0 +1,81 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface PyrightDiagnostic {
6
+ file: string;
7
+ severity: string;
8
+ message: string;
9
+ range?: { start: { line: number; character: number } };
10
+ rule?: string;
11
+ }
12
+
13
+ interface PyrightOutput {
14
+ generalDiagnostics?: PyrightDiagnostic[];
15
+ summary?: {
16
+ errorCount: number;
17
+ warningCount: number;
18
+ informationCount: number;
19
+ };
20
+ }
21
+
22
+ const parser: ParserModule = {
23
+ id: "pyright-json",
24
+ async parse(ctx) {
25
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
26
+ if (!stdout) {
27
+ return {
28
+ tool: "pyright",
29
+ status: "pass",
30
+ summary: "no type errors",
31
+ failures: [],
32
+ logPath: ctx.logPath,
33
+ };
34
+ }
35
+
36
+ let output: PyrightOutput;
37
+ try {
38
+ output = JSON.parse(stdout);
39
+ } catch {
40
+ return {
41
+ tool: "pyright",
42
+ status: "error",
43
+ summary: "failed to parse pyright JSON output",
44
+ logPath: ctx.logPath,
45
+ };
46
+ }
47
+
48
+ const diagnostics = (output.generalDiagnostics ?? []).filter((d) => d.severity === "error");
49
+ const failures: ParsedFailure[] = diagnostics.map((d) => {
50
+ const relPath = path.relative(ctx.cwd, d.file);
51
+ // pyright uses 0-based lines in JSON
52
+ const line = d.range ? d.range.start.line + 1 : undefined;
53
+ // Collapse multi-line messages (detail line after \n) into a single line
54
+ const message = d.message.split("\n")[0];
55
+ return {
56
+ id: `${relPath}:${line}:${d.rule ?? "error"}`,
57
+ file: relPath,
58
+ line,
59
+ message,
60
+ rule: d.rule,
61
+ };
62
+ });
63
+
64
+ const summary = output.summary;
65
+ const parts: string[] = [];
66
+ if (summary) {
67
+ if (summary.errorCount) parts.push(`${summary.errorCount} error${summary.errorCount !== 1 ? "s" : ""}`);
68
+ if (summary.warningCount) parts.push(`${summary.warningCount} warning${summary.warningCount !== 1 ? "s" : ""}`);
69
+ }
70
+
71
+ return {
72
+ tool: "pyright",
73
+ status: failures.length > 0 ? "fail" : "pass",
74
+ summary: parts.length > 0 ? parts.join(", ") : "no type errors",
75
+ failures,
76
+ logPath: ctx.logPath,
77
+ };
78
+ },
79
+ };
80
+
81
+ export default parser;
@@ -1,6 +1,6 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import type { ParserModule } from "../types";
3
+ import { safeReadFile } from "./utils";
4
4
 
5
5
  interface RSpecException {
6
6
  class: string;
@@ -40,7 +40,7 @@ function firstParagraph(message: string): string {
40
40
  const parser: ParserModule = {
41
41
  id: "rspec-json",
42
42
  async parse(ctx) {
43
- const stdout = fs.readFileSync(ctx.stdoutPath, "utf8").trim();
43
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
44
44
  const report = stdout ? (JSON.parse(stdout) as RSpecReport) : null;
45
45
  if (!report) {
46
46
  return {
@@ -0,0 +1,118 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./rubocop-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rubocop-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "rubocop lint_check.rb --format json",
14
+ argv: ["rubocop", "lint_check.rb", "--format", "json"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("rubocop-json parser", () => {
24
+ it("multiple offenses → correct file, line, message, rule, status fail", async () => {
25
+ const stdout = JSON.stringify({
26
+ metadata: {},
27
+ files: [
28
+ {
29
+ path: "lint_check.rb",
30
+ offenses: [
31
+ {
32
+ severity: "warning",
33
+ message: "Lint/UselessAssignment: Useless assignment to variable - `discount`.",
34
+ cop_name: "Lint/UselessAssignment",
35
+ corrected: false,
36
+ location: { start_line: 2, start_column: 3, line: 2, column: 3 },
37
+ },
38
+ {
39
+ severity: "convention",
40
+ message:
41
+ "Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.",
42
+ cop_name: "Style/StringLiterals",
43
+ corrected: false,
44
+ location: { start_line: 6, start_column: 20, line: 6, column: 20 },
45
+ },
46
+ ],
47
+ },
48
+ ],
49
+ summary: { offense_count: 2 },
50
+ });
51
+ const result = await parser.parse(makeCtx(stdout));
52
+ expect(result.status).toBe("fail");
53
+ expect(result.summary).toBe("2 lint errors");
54
+ expect(result.failures).toHaveLength(2);
55
+ expect(result.failures![0]).toMatchObject({
56
+ file: "lint_check.rb",
57
+ line: 2,
58
+ message: "Useless assignment to variable - `discount`.",
59
+ rule: "Lint/UselessAssignment",
60
+ });
61
+ expect(result.failures![1].rule).toBe("Style/StringLiterals");
62
+ });
63
+
64
+ it("no offenses → status pass", async () => {
65
+ const stdout = JSON.stringify({
66
+ metadata: {},
67
+ files: [{ path: "clean.rb", offenses: [] }],
68
+ summary: { offense_count: 0 },
69
+ });
70
+ const result = await parser.parse(makeCtx(stdout));
71
+ expect(result.status).toBe("pass");
72
+ expect(result.failures).toHaveLength(0);
73
+ });
74
+
75
+ it("empty stdout → status pass", async () => {
76
+ const result = await parser.parse(makeCtx(""));
77
+ expect(result.status).toBe("pass");
78
+ });
79
+
80
+ it("absolute file paths → relativized to cwd", async () => {
81
+ const stdout = JSON.stringify({
82
+ metadata: {},
83
+ files: [
84
+ {
85
+ path: "/project/src/foo.rb",
86
+ offenses: [
87
+ { severity: "warning", message: "Lint/Foo: bar", cop_name: "Lint/Foo", location: { line: 1, column: 1 } },
88
+ ],
89
+ },
90
+ ],
91
+ summary: { offense_count: 1 },
92
+ });
93
+ const result = await parser.parse(makeCtx(stdout, "/project"));
94
+ expect(result.failures![0].file).toBe("src/foo.rb");
95
+ });
96
+
97
+ it("strips cop_name prefix from message", async () => {
98
+ const stdout = JSON.stringify({
99
+ metadata: {},
100
+ files: [
101
+ {
102
+ path: "foo.rb",
103
+ offenses: [
104
+ {
105
+ severity: "convention",
106
+ message: "Style/FrozenStringLiteralComment: Missing frozen string literal comment.",
107
+ cop_name: "Style/FrozenStringLiteralComment",
108
+ location: { line: 1, column: 1 },
109
+ },
110
+ ],
111
+ },
112
+ ],
113
+ summary: { offense_count: 1 },
114
+ });
115
+ const result = await parser.parse(makeCtx(stdout));
116
+ expect(result.failures![0].message).toBe("Missing frozen string literal comment.");
117
+ });
118
+ });
@@ -0,0 +1,65 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface RubocopOffense {
6
+ severity: string;
7
+ message: string;
8
+ cop_name: string;
9
+ location: { line: number; column: number };
10
+ }
11
+
12
+ interface RubocopFile {
13
+ path: string;
14
+ offenses: RubocopOffense[];
15
+ }
16
+
17
+ interface RubocopOutput {
18
+ files: RubocopFile[];
19
+ summary: { offense_count: number };
20
+ }
21
+
22
+ const parser: ParserModule = {
23
+ id: "rubocop-json",
24
+ async parse(ctx) {
25
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
26
+ if (!stdout) {
27
+ return { tool: "rubocop", status: "pass", summary: "no lint errors", failures: [], logPath: ctx.logPath };
28
+ }
29
+
30
+ let data: RubocopOutput;
31
+ try {
32
+ data = JSON.parse(stdout) as RubocopOutput;
33
+ } catch {
34
+ return { tool: "rubocop", status: "error", summary: "failed to parse rubocop JSON output", logPath: ctx.logPath };
35
+ }
36
+
37
+ const failures: ParsedFailure[] = [];
38
+ for (const file of data.files) {
39
+ const relPath = path.isAbsolute(file.path) ? path.relative(ctx.cwd, file.path) : file.path;
40
+ for (const o of file.offenses) {
41
+ // Strip the "CopName: " prefix from the message if present.
42
+ // Escape special regex chars in cop_name (e.g. "." in Style/Foo.Bar).
43
+ const escapedCop = o.cop_name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
44
+ const msg = o.message.replace(new RegExp(`^${escapedCop}:\\s*`), "");
45
+ failures.push({
46
+ id: `${relPath}:${o.location.line}:${o.cop_name}`,
47
+ file: relPath,
48
+ line: o.location.line,
49
+ message: msg,
50
+ rule: o.cop_name,
51
+ });
52
+ }
53
+ }
54
+
55
+ return {
56
+ tool: "rubocop",
57
+ status: failures.length > 0 ? "fail" : "pass",
58
+ summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
59
+ failures,
60
+ logPath: ctx.logPath,
61
+ };
62
+ },
63
+ };
64
+
65
+ export default parser;
@@ -1,6 +1,6 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import type { ParserModule } from "../types";
3
+ import { safeReadFile } from "./utils";
4
4
 
5
5
  interface RuffItem {
6
6
  filename: string;
@@ -12,7 +12,7 @@ interface RuffItem {
12
12
  const parser: ParserModule = {
13
13
  id: "ruff-json",
14
14
  async parse(ctx) {
15
- const stdout = fs.readFileSync(ctx.stdoutPath, "utf8").trim();
15
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
16
16
  const items = stdout ? (JSON.parse(stdout) as RuffItem[]) : [];
17
17
  const failures = (Array.isArray(items) ? items : []).map((item) => {
18
18
  const relPath = path.relative(ctx.cwd, item.filename);
@@ -0,0 +1,110 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./shellcheck-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "shellcheck-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "shellcheck lint_check.sh --format=json",
14
+ argv: ["shellcheck", "lint_check.sh", "--format=json"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("shellcheck-json parser", () => {
24
+ it("multiple lint errors → correct file, line, message, rule, status fail", async () => {
25
+ const stdout = JSON.stringify([
26
+ {
27
+ file: "lint_check.sh",
28
+ line: 4,
29
+ endLine: 4,
30
+ column: 6,
31
+ endColumn: 15,
32
+ level: "info",
33
+ code: 2086,
34
+ message: "Double quote to prevent globbing and word splitting.",
35
+ fix: null,
36
+ },
37
+ {
38
+ file: "lint_check.sh",
39
+ line: 6,
40
+ endLine: 6,
41
+ column: 10,
42
+ endColumn: 21,
43
+ level: "error",
44
+ code: 2045,
45
+ message: "Iterating over ls output is fragile. Use globs.",
46
+ fix: null,
47
+ },
48
+ ]);
49
+ const result = await parser.parse(makeCtx(stdout));
50
+ expect(result.status).toBe("fail");
51
+ expect(result.summary).toBe("2 lint errors");
52
+ expect(result.failures).toHaveLength(2);
53
+ expect(result.failures![0]).toMatchObject({
54
+ file: "lint_check.sh",
55
+ line: 4,
56
+ message: "Double quote to prevent globbing and word splitting.",
57
+ rule: "SC2086",
58
+ });
59
+ expect(result.failures![1]).toMatchObject({
60
+ file: "lint_check.sh",
61
+ line: 6,
62
+ message: "Iterating over ls output is fragile. Use globs.",
63
+ rule: "SC2045",
64
+ });
65
+ });
66
+
67
+ it("no errors (empty array) → status pass", async () => {
68
+ const result = await parser.parse(makeCtx("[]"));
69
+ expect(result.status).toBe("pass");
70
+ expect(result.summary).toBe("no lint errors");
71
+ expect(result.failures).toHaveLength(0);
72
+ });
73
+
74
+ it("empty stdout → status pass", async () => {
75
+ const result = await parser.parse(makeCtx(""));
76
+ expect(result.status).toBe("pass");
77
+ expect(result.failures).toHaveLength(0);
78
+ });
79
+
80
+ it("absolute file paths → relativized to cwd", async () => {
81
+ const stdout = JSON.stringify([
82
+ {
83
+ file: "/project/scripts/deploy.sh",
84
+ line: 10,
85
+ column: 5,
86
+ level: "warning",
87
+ code: 2034,
88
+ message: "foo appears unused.",
89
+ },
90
+ ]);
91
+ const result = await parser.parse(makeCtx(stdout, "/project"));
92
+ expect(result.failures![0].file).toBe("scripts/deploy.sh");
93
+ expect(result.failures![0].file).not.toContain("/project");
94
+ });
95
+
96
+ it("rule code is prefixed with SC", async () => {
97
+ const stdout = JSON.stringify([
98
+ {
99
+ file: "test.sh",
100
+ line: 1,
101
+ column: 1,
102
+ level: "info",
103
+ code: 2035,
104
+ message: "Use ./*glob* or -- *glob* so names with dashes won't become options.",
105
+ },
106
+ ]);
107
+ const result = await parser.parse(makeCtx(stdout));
108
+ expect(result.failures![0].rule).toBe("SC2035");
109
+ });
110
+ });
@@ -0,0 +1,61 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface ShellCheckItem {
6
+ file: string;
7
+ line: number;
8
+ column: number;
9
+ level: string;
10
+ code: number;
11
+ message: string;
12
+ }
13
+
14
+ const parser: ParserModule = {
15
+ id: "shellcheck-json",
16
+ async parse(ctx) {
17
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
18
+ if (!stdout || stdout === "[]") {
19
+ return {
20
+ tool: "shellcheck",
21
+ status: "pass",
22
+ summary: "no lint errors",
23
+ failures: [],
24
+ logPath: ctx.logPath,
25
+ };
26
+ }
27
+
28
+ let items: ShellCheckItem[];
29
+ try {
30
+ items = JSON.parse(stdout) as ShellCheckItem[];
31
+ } catch {
32
+ return {
33
+ tool: "shellcheck",
34
+ status: "error",
35
+ summary: "failed to parse shellcheck JSON output",
36
+ logPath: ctx.logPath,
37
+ };
38
+ }
39
+
40
+ const failures: ParsedFailure[] = items.map((item) => {
41
+ const relPath = path.isAbsolute(item.file) ? path.relative(ctx.cwd, item.file) : item.file;
42
+ return {
43
+ id: `${relPath}:${item.line}:SC${item.code}`,
44
+ file: relPath,
45
+ line: item.line,
46
+ message: item.message,
47
+ rule: `SC${item.code}`,
48
+ };
49
+ });
50
+
51
+ return {
52
+ tool: "shellcheck",
53
+ status: failures.length > 0 ? "fail" : "pass",
54
+ summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
55
+ failures,
56
+ logPath: ctx.logPath,
57
+ };
58
+ },
59
+ };
60
+
61
+ export default parser;