ziglint Changelog View on GitHub

Z035: Use alias instead of qualified path

Reports a qualified path when a top-level alias for that path exists. For example, with const testing = std.testing; in the file, a call to std.testing.expect(...) is reported and the message recommends testing.expect(...).

The declaration is not the problem. The check reports the use that bypasses an alias already in scope. This catches the inconsistency where one test uses the alias and a newly added test spells the full path.

Examples

Bad

One test uses the alias, the other does not:

const std = @import("std");
const testing = std.testing;

test "first" {
    try testing.expect(true);
}

test "second" {
    // expect: Z035
    try std.testing.expect(true);
}

The same applies to namespace aliases:

const std = @import("std");
const mem = std.mem;

fn clone(allocator: std.mem.Allocator) void { // expect: Z035
    _ = allocator;
}

Good

Use the alias in every place:

const std = @import("std");
const testing = std.testing;

test "first" {
    try testing.expect(true);
}

test "second" {
    try testing.expect(true);
}

A declaration by itself is not reported:

const std = @import("std");
const testing = std.testing;

A qualified path without an alias for it is not reported:

const std = @import("std");

test "example" {
    try std.testing.expect(true);
}

Limitations

The check only collects top-level aliases. An alias declared inside a function or a container is not tracked.

The alias must be initialized directly from a path such as std.testing. Initializers with calls, conditionals, or other expressions are not tracked.

The check compares path text and does not resolve shadowed names. A local binding that shadows the path root can cause a false positive.

A use is skipped when it is an argument to a call, or an operand of == or !=, that also names the alias elsewhere in the expression. This keeps tests such as expectEqual(alias, path) from receiving a suggestion that would make the comparison vacuous.

This rule reports qualified uses only. It does not report an alias declaration that is never used at all.

Rationale

Two names for the same declaration make the file read differently depending on where the reader is. The long form is also the one that survives every refactor, because the compiler cannot notice that the alias was intended. Reporting the bypassing use makes the code converge on one spelling.