Skip to documentation
SLOP

tiny.smg.command.check

Reference tiny.smg command check

Defined in command.

API (8)

Actions

Public operations.

Namespaces

Public namespaces.

No direct callersNo direct callscommandcheck
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: tools/smg/src/command/check/render.zig:10

zig
pub fn failed(findings: []const rules.Finding, dead: []const rules.DeadRule) bool {    return findings.len != 0 or dead.len != 0;}
Called byCallsNo direct callstest; no linktools.smg.src.command.check.rendertest: check failure includes dead rul...command.checkruncommand.checkfailed
Static calls · unresolved targets: 0 · external targets: 0.

Source: tools/smg/src/command/check/render.zig:29

zig
pub fn writeJson(allocator: std.mem.Allocator, writer: *std.Io.Writer, rules_checked: usize, findings: []const rules.Finding, dead: []const rules.DeadRule, is_failed: bool) !void {    var out = pretty_json.Writer.init(writer, .minified);    try out.beginObject();    try out.objectField("rules_checked");    try out.write(rules_checked);    try out.objectField("violations");    try out.beginArray();    for (findings) |finding| try json.writeFinding(allocator, &out, finding);    try out.endArray();    try out.objectField("dead_rules");    try out.beginArray();    for (dead) |dead_rule| {        try out.beginObject();        try out.objectField("rule");        try out.write(dead_rule.rule);        try out.objectField("reason");        try out.write(dead_rule.reason);        try out.endObject();    }    try out.endArray();    try out.objectField("status");    try out.write(if (!is_failed) "pass" else "fail");    try out.endObject();    try writer.writeByte('\n');}
Called byCallsNo direct callerscli.jsonwriteFindingcommand.checkwriteJson
Static calls · unresolved targets: 1 · external targets: 7.

Source: tools/smg/src/command/check/render.zig:14

zig
pub fn writeNoRulesJson(writer: *std.Io.Writer) !void {    var out = pretty_json.Writer.init(writer, .minified);    try out.beginObject();    try out.objectField("rules");    try out.beginArray();    try out.endArray();    try out.objectField("violations");    try out.beginArray();    try out.endArray();    try out.objectField("status");    try out.write("no_rules");    try out.endObject();    try writer.writeByte('\n');}
Called byCallsNo direct callscommand.checkruncommand.checkwriteNoRulesJson
Static calls · unresolved targets: 1 · external targets: 7.

Source: tools/smg/src/command/check/render.zig:55

zig
pub fn writeText(allocator: std.mem.Allocator, writer: *std.Io.Writer, rule_list: []const rules.Rule, findings: []const rules.Finding, full: bool) !void {    for (rule_list) |rule| {        const finding = findingFor(findings, rule.name);        if (finding == null) {            try writer.print("PASS  {s}\n", .{rule.name});            continue;        }        try writer.print("FAIL  {s}: {s}\n", .{ rule.name, finding.?.message });        const witnesses = try findingWitnesses(allocator, finding.?);        const limit = if (full) witnesses.len else @min(witnesses.len, @as(usize, 10));        for (witnesses[0..limit]) |line| try writer.print("        {s}\n", .{line});        if (!full and witnesses.len > limit) try writer.print("        ... and {d} more (use --full)\n", .{witnesses.len - limit});    }}
Called byCallstest; no linktools.smg.src.command.check.rendertest: check renders quantified predic...test; no linktools.smg.src.command.check.rendertest: check text renders pass fail an...private; no linktools.smg.src.command.check.renderfindingForprivate; no linktools.smg.src.command.check.renderfindingWitnessescommand.checkwriteText
Static calls · unresolved targets: 2 · external targets: 0.

Source: tools/smg/src/command/check/run.zig:13

zig
pub fn run(    allocator: std.mem.Allocator,    root: []const u8,    graph: graph_mod.Graph,    concept_list: []const concepts.Concept,    args: []const []const u8,    limits: smg.Limits,) !u8 {    const list = try rules.load(allocator, root, limits.storage);    const pos = try options.positional(allocator, args);    if (list.len == 0) {        if (options.hasJson(args)) {            var out: std.Io.Writer.Allocating = .init(allocator);            try render.writeNoRulesJson(&out.writer);            _ = try output.writeOut(out.written());            return 1;        }        const rules_path = try storage.files.rulesPath(allocator, root);        try output.writeErrFmt(allocator, "Error: no rules defined; the check enforces nothing. Seed {s} or add one with smg rule add.\n", .{rules_path});        return 1;    }    const checked_rules = try selection.selected(allocator, list, if (pos.len == 0) null else pos[0]);    if (checked_rules.len == 0 and pos.len != 0) {        try output.writeErrFmt(allocator, "Error: rule '{s}' not found.\n", .{pos[0]});        return 1;    }    if (try rules.quantifiedMetricValidationMessage(allocator, graph, checked_rules)) |message| {        try output.writeWrappedError(allocator, message);        return 2;    }    var found: std.ArrayList(rules.Finding) = .empty;    var prepared: rules.Check = undefined;    prepared.prepare(graph, limits.analysis);    for (checked_rules) |rule| {        const maybe_finding = prepared.rule(allocator, rule, concept_list) catch |err| {            if (try rules.checkErrorMessage(allocator, rule, err)) |message| {                try output.writeWrappedError(allocator, message);                return 2;            }            return err;        };        if (maybe_finding) |finding| try found.append(allocator, finding);    }    const findings = try found.toOwnedSlice(allocator);    const dead = try rules.deadRules(allocator, graph, checked_rules);    const is_failed = render.failed(findings, dead);    if (options.hasJson(args)) {        var out: std.Io.Writer.Allocating = .init(allocator);        try render.writeJson(allocator, &out.writer, checked_rules.len, findings, dead, is_failed);        _ = try output.writeOut(out.written());    } else {        var out: std.Io.Writer.Allocating = .init(allocator);        try render.writeText(allocator, &out.writer, checked_rules, findings, options.hasFlag(args, "--full"));        _ = try output.writeOut(out.written());    }    if (!options.hasJson(args)) {        for (dead) |dead_rule| {            try output.writeErrFmt(allocator, "warning: rule '{s}' cannot fire: {s}\n", .{ dead_rule.rule, dead_rule.reason });        }    }    return if (!is_failed) 0 else 1;}
Called byCallsNo direct callerscli.optionshasFlagcli.optionshasJsoncli.optionspositionalcli.outputwriteErrFmtcli.outputwriteOut+11 morecommand.checkrun
Static calls · unresolved targets: 1 · external targets: 4.

Source: tools/smg/src/command/check/selection.zig:6

zig
pub fn selected(allocator: std.mem.Allocator, rule_list: []const rules.Rule, maybe_name: ?[]const u8) ![]const rules.Rule {    if (maybe_name == null) return rule_list;    var out: std.ArrayList(rules.Rule) = .empty;    for (rule_list) |rule| if (std.mem.eql(u8, rule.name, maybe_name.?)) try out.append(allocator, rule);    return try out.toOwnedSlice(allocator);}
Called byCallsNo direct callstiny.profilinganalyze.comparemissingWorkloadsprivate; no linksrc.profiling.commandwriteAllocationCoverageJsonprivate; no linksrc.profiling.commandwritePlanJsonprivate; no linksrc.profiling.commandwritePlanTextprivate; no linksrc.profiling.commandwriteRunDryRunText+9 morecommand.checkselected
Static calls · unresolved targets: 1 · external targets: 1.

Source: tools/smg/src/command/check/root.zig

zig
pub const command = @import("command.zig");pub const refresh = @import("refresh.zig");const render = @import("render.zig");const runner = @import("run.zig");const selection = @import("selection.zig");pub const failed = render.failed;pub const run = runner.run;pub const selected = selection.selected;pub const writeJson = render.writeJson;pub const writeNoRulesJson = render.writeNoRulesJson;pub const writeText = render.writeText;

Source: tools/smg/src/command/root.zig:7

zig
pub const check = @import("check/root.zig");

Complete call list for command.check.run

16 direct calls.

Complete caller list for command.check.selected

14 direct callers.

Audit

Definitions7
Public names7
Members0
Version26.7.0
Revisiondaab053ee433