Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/zig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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| {
Expand Down
6 changes: 3 additions & 3 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading