包文件→ .shtukbase/packages/quality/checks/q09_goals_coverage.ts
checks/q09_goals_coverage.ts
24 行, 1.3 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // QLT-R09 (observe). A sensor, not a check: lists the goals (layer "Business", type Goal) that have no benefit in
- // operation (an Outcome with `goal` on them) or no indicator of potential (an Indicator whose `outcomes` names one
- // of those benefits). Prints one line per goal with a gap and always exits 0: the norm only observes.
- import { Project } from '../../collections/checks/lib/speclib.ts';
- import { addr, fld, refs } from './lib/qlib.ts';
- export function gaps(p: Project): string[] {
- if (!p.coll('GOAL')) return [];
- const fGoal = fld(p, 'OUT', 'GOAL', 'goal');
- const fOut = fld(p, 'IND', 'OUT', 'outcomes');
- const out: string[] = [];
- for (const g of p.records('GOAL')) {
- const outs = p.records('OUT').filter((o) => refs(p, o, fGoal, 'GOAL').includes(g.id)).map((o) => o.id);
- const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && refs(p, i, fOut, 'OUT').some((x) => outs.includes(x)));
- const lack = [!outs.length && 'benefit in operation', !inds.length && 'indicator of potential'].filter(Boolean);
- if (lack.length) out.push(`${addr(g.id)}: the goal has no ${lack.join(' and ')}`);
- }
- return out;
- }
- if (import.meta.main) {
- const lines = gaps(new Project(process.cwd()));
- console.log(lines.length ? lines.join('\n') : 'every goal has a benefit and an indicator (or there are no goals)');
- }