tiny.smg.command.check
Defined in command.
API (8)
Actions
Public operations.
Namespaces
Public namespaces.
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;}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');}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');}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}); }}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;}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);}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.
tiny.smg.cli.options.hasFlag[function] attools/smg/src/cli/options.zig:101tiny.smg.cli.options.hasJson[function] attools/smg/src/cli/options.zig:141tiny.smg.cli.options.positional[function] attools/smg/src/cli/options.zig:35tiny.smg.cli.output.writeErrFmt[function] attools/smg/src/cli/output.zig:27tiny.smg.cli.output.writeOut[function] attools/smg/src/cli/output.zig:8tiny.smg.cli.output.writeWrappedError[function] attools/smg/src/cli/output.zig:51tiny.smg.command.check.failed[function] attools/smg/src/command/check/render.zig:10tiny.smg.command.check.writeNoRulesJson[function] attools/smg/src/command/check/render.zig:14tiny.smg.command.check.selected[function] attools/smg/src/command/check/selection.zig:6tiny.smg.rules.Check.prepare[method] attools/smg/src/rules.zig:528tiny.smg.rules.Check.rule[method] attools/smg/src/rules.zig:534tiny.smg.rules.checkErrorMessage[function] attools/smg/src/rules.zig:1684tiny.smg.rules.deadRules[function] attools/smg/src/rules.zig:626tiny.smg.rules.load[function] attools/smg/src/rules.zig:369tiny.smg.rules.quantifiedMetricValidationMessage[function] attools/smg/src/rules.zig:1287tiny.smg.storage.files.rulesPath[function] attools/smg/src/storage/files.zig:9
Complete caller list for command.check.selected
14 direct callers.
tiny.profiling.analyze.compare.missingWorkloads[function] atsrc/profiling/analyze/compare.zig:46src.profiling.command.writeAllocationCoverageJson[function] — private; no exact target atsrc/profiling/command.zig:1107in nearest public ownertiny.profiling.commandsrc.profiling.command.writePlanJson[function] — private; no exact target atsrc/profiling/command.zig:935in nearest public ownertiny.profiling.commandsrc.profiling.command.writePlanText[function] — private; no exact target atsrc/profiling/command.zig:542in nearest public ownertiny.profiling.commandsrc.profiling.command.writeRunDryRunText[function] — private; no exact target atsrc/profiling/command.zig:571in nearest public ownertiny.profiling.commandsrc.profiling.command.writeRunPlanWorkloadsJson[function] — private; no exact target atsrc/profiling/command.zig:1022in nearest public ownertiny.profiling.commandsrc.profiling.driver.validation.validateBinaryScope[function] — private; no exact target atsrc/profiling/driver/validation.zig:84in nearest public ownertiny.profiling.driver.validationsrc.profiling.driver.validation.validateChildConfigurationScope[function] — private; no exact target atsrc/profiling/driver/validation.zig:97in nearest public ownertiny.profiling.driver.validationtiny.profiling.plan.allocationCoverage[function] atsrc/profiling/plan.zig:78tiny.profiling.plan.collect[function] atsrc/profiling/plan.zig:107tiny.profiling.plan.precedingNames[function] atsrc/profiling/plan.zig:115tiny.profiling.report.coverage.writeRunArtifacts[function] atsrc/profiling/report/coverage.zig:72tiny.smg.command.check.run[function] attools/smg/src/command/check/run.zig:13tools.smg.src.command.check.selection.test_check_selected_rules_preserve_all_singleton_and_empty_cases[function] — test; no exact target attools/smg/src/command/check/selection.zig:13in nearest public ownertools.smg.src.command.check.selection
Audit
| Definitions | 7 |
|---|---|
| Public names | 7 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |