From e2c7e124ec877d4c57f6e3ea350d803fe2c065e1 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:11:14 -0400 Subject: [PATCH 1/6] chore: update root.zig for Zig 0.15.1 writer and allocator changes --- src/root.zig | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/root.zig b/src/root.zig index 057538a..c98a44c 100644 --- a/src/root.zig +++ b/src/root.zig @@ -451,8 +451,13 @@ const sarif_schema: []const u8 = "https://json.schemastore.org/sarif-2.1.0.json" /// Emits all diagnostics in SARIF format to the given writer. /// Supports version 2.1.0. Includes rule metadata if code is set. -pub fn emitSarif(diagnostics: []const Diagnostic, writer: anytype) !void { - var buf_writer = json.writeStream(writer, .{}); +pub fn emitSarif( + allocator: Allocator, + capacity: usize, + diagnostics: []const Diagnostic, + writer: *std.io.Writer, +) !void { + var buf_writer = json.Stringify{ .writer = writer }; try buf_writer.beginObject(); @@ -485,8 +490,8 @@ pub fn emitSarif(diagnostics: []const Diagnostic, writer: anytype) !void { try buf_writer.objectField("rules"); try buf_writer.beginArray(); - var seen_codes = std.ArrayList([]const u8).init(std.heap.page_allocator); - defer seen_codes.deinit(); + var seen_codes = try std.ArrayList([]const u8).initCapacity(allocator, capacity); + defer seen_codes.deinit(allocator); for (diagnostics) |d| { if (d.code) |code| { @@ -499,7 +504,7 @@ pub fn emitSarif(diagnostics: []const Diagnostic, writer: anytype) !void { } if (!already_added) { - try seen_codes.append(code); + try seen_codes.append(allocator, code); try buf_writer.beginObject(); // rule From 32b5ff88522fa68202c324fd2dd59ec8ef0d1398 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:11:22 -0400 Subject: [PATCH 2/6] test: update tests to match Zig 0.15.1 writer and allocator changes --- src/tests.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tests.zig b/src/tests.zig index ec82246..fc16e3c 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -185,10 +185,15 @@ test "emitSarif outputs valid JSON with basic diagnostic" { .withLocation("main.zig", 3, 4) .withCode("E001"); - var stream = std.io.fixedBufferStream(&buffer); - try felher.emitSarif(&[_]Diagnostic{ diag1, diag2 }, stream.writer()); - - const json = buffer[0..stream.pos]; + var stream = std.io.Writer.fixed(&buffer); + try felher.emitSarif( + std.heap.page_allocator, + 256, + &[_]Diagnostic{ diag1, diag2 }, + &stream, + ); + + const json = buffer[0..stream.end]; try testing.expect(std.mem.indexOf(u8, json, "\"message\"") != null); try testing.expect(std.mem.indexOf(u8, json, "invalid token") != null); try testing.expect(std.mem.indexOf(u8, json, "main.zig") != null); From 614c5b5ca93a261857bf322c74446e17533642a2 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:11:40 -0400 Subject: [PATCH 3/6] docs: update README for Zig 0.15.1 changes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df8ae46..2d42856 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ reporter.reportMany(&diagnostics); Exports diagnostics to SARIF format (version 2.1.0) as a JSON stream. ```zig -try emitSarif(diagnostics, writer); +try emitSarif(allocator, capacity, diagnostics, writer); ``` Writes a `runs` array with all diagnostics as SARIF `results`. If a `code` is set, it's included as a rule ID. @@ -233,7 +233,7 @@ Writes a `runs` array with all diagnostics as SARIF `results`. If a `code` is se const file = try std.fs.cwd().createFile("report.sarif.json", .{}); defer file.close(); -try emitSarif(&[_]Diagnostic{diag}, file.writer()); +try emitSarif(std.heap.page_allocator, 256, &[_]Diagnostic{diag}, file.writer()); ``` Use this to integrate with editors or CI tools that support SARIF (e.g. GitHub, VS Code, etc). From d0599e4b9bcd356e13b198af50fb7a4f9ff79703 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:11:49 -0400 Subject: [PATCH 4/6] chore: set minimum_zig_version to 0.15.1 --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index 90c0732..7c169ef 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = .fehler, .version = "0.5.1", .fingerprint = 0x2763d78399d579f0, - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.1", .dependencies = .{}, .paths = .{ "build.zig", From ddfaf5c99d8fe2abd24aaf92ea1bac8587b42b37 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:12:53 -0400 Subject: [PATCH 5/6] ci: update GitHub Actions workflow to Zig 0.15.1 --- .github/workflows/zig.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/zig.yml b/.github/workflows/zig.yml index a09ce8a..13df2f8 100644 --- a/.github/workflows/zig.yml +++ b/.github/workflows/zig.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: mlugg/setup-zig@v2 with: - version: 0.14.1 + version: 0.15.1 - name: "Run the tests." run: zig test src/tests.zig From 9e9bbd33b13fc32e59c0a595f22adf3bf840c6d8 Mon Sep 17 00:00:00 2001 From: ciathefed Date: Tue, 26 Aug 2025 17:22:45 -0400 Subject: [PATCH 6/6] chore: remove unnecessary capacity handling with ArrayList unmanaged default --- README.md | 4 ++-- src/root.zig | 13 ++++--------- src/tests.zig | 7 +------ 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2d42856..d813c2f 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ reporter.reportMany(&diagnostics); Exports diagnostics to SARIF format (version 2.1.0) as a JSON stream. ```zig -try emitSarif(allocator, capacity, diagnostics, writer); +try emitSarif(allocator, diagnostics, writer); ``` Writes a `runs` array with all diagnostics as SARIF `results`. If a `code` is set, it's included as a rule ID. @@ -233,7 +233,7 @@ Writes a `runs` array with all diagnostics as SARIF `results`. If a `code` is se const file = try std.fs.cwd().createFile("report.sarif.json", .{}); defer file.close(); -try emitSarif(std.heap.page_allocator, 256, &[_]Diagnostic{diag}, file.writer()); +try emitSarif(std.heap.page_allocator, &[_]Diagnostic{diag}, file.writer()); ``` Use this to integrate with editors or CI tools that support SARIF (e.g. GitHub, VS Code, etc). diff --git a/src/root.zig b/src/root.zig index c98a44c..3c941d4 100644 --- a/src/root.zig +++ b/src/root.zig @@ -451,12 +451,7 @@ const sarif_schema: []const u8 = "https://json.schemastore.org/sarif-2.1.0.json" /// Emits all diagnostics in SARIF format to the given writer. /// Supports version 2.1.0. Includes rule metadata if code is set. -pub fn emitSarif( - allocator: Allocator, - capacity: usize, - diagnostics: []const Diagnostic, - writer: *std.io.Writer, -) !void { +pub fn emitSarif(allocator: Allocator, diagnostics: []const Diagnostic, writer: *std.io.Writer) !void { var buf_writer = json.Stringify{ .writer = writer }; try buf_writer.beginObject(); @@ -490,8 +485,8 @@ pub fn emitSarif( try buf_writer.objectField("rules"); try buf_writer.beginArray(); - var seen_codes = try std.ArrayList([]const u8).initCapacity(allocator, capacity); - defer seen_codes.deinit(allocator); + var seen_codes = std.array_list.Managed([]const u8).init(allocator); + defer seen_codes.deinit(); for (diagnostics) |d| { if (d.code) |code| { @@ -504,7 +499,7 @@ pub fn emitSarif( } if (!already_added) { - try seen_codes.append(allocator, code); + try seen_codes.append(code); try buf_writer.beginObject(); // rule diff --git a/src/tests.zig b/src/tests.zig index fc16e3c..b0beeee 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -186,12 +186,7 @@ test "emitSarif outputs valid JSON with basic diagnostic" { .withCode("E001"); var stream = std.io.Writer.fixed(&buffer); - try felher.emitSarif( - std.heap.page_allocator, - 256, - &[_]Diagnostic{ diag1, diag2 }, - &stream, - ); + try felher.emitSarif(std.heap.page_allocator, &[_]Diagnostic{ diag1, diag2 }, &stream); const json = buffer[0..stream.end]; try testing.expect(std.mem.indexOf(u8, json, "\"message\"") != null);