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 diff --git a/README.md b/README.md index df8ae46..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(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(&[_]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/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", diff --git a/src/root.zig b/src/root.zig index 057538a..3c941d4 100644 --- a/src/root.zig +++ b/src/root.zig @@ -451,8 +451,8 @@ 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, diagnostics: []const Diagnostic, writer: *std.io.Writer) !void { + var buf_writer = json.Stringify{ .writer = writer }; try buf_writer.beginObject(); @@ -485,7 +485,7 @@ 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); + var seen_codes = std.array_list.Managed([]const u8).init(allocator); defer seen_codes.deinit(); for (diagnostics) |d| { diff --git a/src/tests.zig b/src/tests.zig index ec82246..b0beeee 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -185,10 +185,10 @@ 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()); + var stream = std.io.Writer.fixed(&buffer); + try felher.emitSarif(std.heap.page_allocator, &[_]Diagnostic{ diag1, diag2 }, &stream); - const json = buffer[0..stream.pos]; + 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);