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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.zig-cache/
.zig-global-cache/
zig-out/
*.o
18 changes: 4 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,17 @@ pub fn build(b: *std.Build) void {
const fmt_check = b.addFmt(.{ .paths = &.{ "src", "build.zig", "build.zig.zon" } });
test_step.dependOn(&fmt_check.step);

// Self-lint: the public `addLint` API enforces exit code 0 (so downstream
// users can fail their CI on findings). For our own `zig build test`
// aggregate we want to ensure ziglint doesn't *crash* on its own source,
// but we tolerate the residual lint findings (mostly stylistic) that
// remain after the Zig 0.16 migration.
const lint_step = addLint(b, exe, &.{ b.path("src"), b.path("build.zig") });
const lint_alias = b.step("lint", "Run ziglint on this repository");
lint_alias.dependOn(lint_step);

// A separate "self-lint smoke" run gated into `zig build test`.
// Ziglint currently reports residual style findings (Z011/Z012/Z013/Z023)
// against its own Zig 0.16-migrated source. Until those are addressed we
// expect exit code 1 (findings reported), which still proves ziglint did
// not crash (segfault/ABRT). When the codebase becomes lint-clean this
// will start failing -- swap to `expectExitCode(0)` at that point.
// Keep self-lint in the test aggregate so regressions break the normal gate.
const lint_smoke = b.addRunArtifact(exe);
lint_smoke.addDirectoryArg(b.path("src"));
lint_smoke.addFileArg(b.path("build.zig"));
addPathInputs(b, lint_smoke, b.path("src"));
addPathInputs(b, lint_smoke, b.path("build.zig"));
lint_smoke.expectExitCode(1);
lint_smoke.expectExitCode(0);
test_step.dependOn(&lint_smoke.step);
}

Expand Down Expand Up @@ -133,10 +123,10 @@ fn getVersion(b: *std.Build) []const u8 {
const trimmed = std.mem.trim(u8, git_describe, " \n\r");
const without_v = if (trimmed.len > 0 and trimmed[0] == 'v') trimmed[1..] else trimmed;

if (std.mem.indexOfScalar(u8, without_v, '-')) |dash_idx| {
if (std.mem.findScalar(u8, without_v, '-')) |dash_idx| {
const tag_part = without_v[0..dash_idx];
const rest = without_v[dash_idx + 1 ..];
if (std.mem.indexOfScalar(u8, rest, '-')) |second_dash| {
if (std.mem.findScalar(u8, rest, '-')) |second_dash| {
const count = rest[0..second_dash];
const hash = rest[second_dash + 1 ..];
const hash_without_g = if (hash.len > 0 and hash[0] == 'g') hash[1..] else hash;
Expand Down
16 changes: 8 additions & 8 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ pub fn setRuleEnabled(self: *Config, rule: Rule, enabled: bool) void {
}

/// Load config from .ziglint.zon file, searching from start_path up to root.
pub fn load(io: std.Io, allocator: std.mem.Allocator, start_path: ?[]const u8) !Config {
const config_path = try findConfigFile(io, allocator, start_path) orelse return .{};
pub fn load(allocator: std.mem.Allocator, io: std.Io, start_path: ?[]const u8) !Config {
const config_path = try findConfigFile(allocator, io, start_path) orelse return .{};
defer allocator.free(config_path);

return parseConfigFile(io, allocator, config_path) catch |err| {
return parseConfigFile(allocator, io, config_path) catch |err| {
std.debug.print("warning: failed to parse {s}: {}\n", .{ config_path, err });
return .{};
};
}

/// Find .ziglint.zon by walking up from start_path.
fn findConfigFile(io: std.Io, allocator: std.mem.Allocator, start_path: ?[]const u8) !?[]const u8 {
fn findConfigFile(allocator: std.mem.Allocator, io: std.Io, start_path: ?[]const u8) !?[]const u8 {
const path = start_path orelse {
return findConfigInDir(io, allocator, ".");
return findConfigInDir(allocator, io, ".");
};

const abs_path_z = std.Io.Dir.cwd().realPathFileAlloc(io, path, allocator) catch null;
Expand All @@ -61,7 +61,7 @@ fn findConfigFile(io: std.Io, allocator: std.mem.Allocator, start_path: ?[]const

var current = abs_path;
while (true) {
if (try findConfigInDir(io, allocator, current)) |config_path| {
if (try findConfigInDir(allocator, io, current)) |config_path| {
return config_path;
}

Expand All @@ -73,7 +73,7 @@ fn findConfigFile(io: std.Io, allocator: std.mem.Allocator, start_path: ?[]const
return null;
}

fn findConfigInDir(io: std.Io, allocator: std.mem.Allocator, dir_path: []const u8) !?[]const u8 {
fn findConfigInDir(allocator: std.mem.Allocator, io: std.Io, dir_path: []const u8) !?[]const u8 {
const config_path = try std.fs.path.join(allocator, &.{ dir_path, ".ziglint.zon" });
errdefer allocator.free(config_path);

Expand All @@ -91,7 +91,7 @@ const ZonConfig = struct {
rules: ?Rule.Config = null,
};

fn parseConfigFile(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !Config {
fn parseConfigFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !Config {
const source = try std.Io.Dir.cwd().readFileAllocOptions(
io,
path,
Expand Down
Loading
Loading