English
explain
Turn a validator's message into a problem an author can act on, and print it as alta lint does.
Example
example.mjs
js
// Read a problem as an author: the field, the rule, how to fix it, and the page that explains it.
import { formatProblem, ruleInfo, ruleUrl, validate } from "@altasystem/sdk";
const doc = {
schema: "alta.quests/0.3",
id: "my-pack",
branch: "core",
quests: [{
uid: "core.my-pack.hello",
title: { en: "Hello", fr: "Salut" },
act: 1,
giver: "daemon",
steps: [{ id: "wave", kind: "manual", title: { en: "Wave at your agent", fr: "Fais signe à ton agent" } }],
reward: { xp: 10 },
}],
};
for (const p of validate(doc).problems) {
console.log(formatProblem(p, "quests.json"));
console.log("fix:", ruleInfo(p.rule)?.fix);
console.log("docs:", ruleUrl(p.rule));
}Run it from a folder where the package is installed: node example.mjs.
Output
text
error: quests.json › quests[0].steps[0].human: core.my-pack.hello/wave: a manual step says why only the player can do it (human) [step.manual-reason] (see https://docs.os.altasystem.ai/reference/errors#step-manual-reason)
fix: Add `"human"`: speak, approve, device, external, judge or before; or give the step a `run` and a `check`.
docs: https://docs.os.altasystem.ai/reference/errors#step-manual-reasonFunctions
explain
ts
function explain(kind: string, messages: string[], doc: unknown, level: Problem["level"] = "error"): Problem[]Explains the messages of a validator for a document of this kind.
formatProblem
ts
function formatProblem(p: Problem, file?: string): stringOne line for a terminal: file › field: message [rule] (see <the rule on the errors page>).
ruleInfo
ts
const ruleInfo = (id: string): RuleInfo | undefinedThe rule of an id, or undefined.
ruleUrl
ts
const ruleUrl = (id: string)The page that explains a rule.