ShtukbaseStandard
包文件→ .shtukbase/packages/quality/checks/q09_goals_coverage.ts

checks/q09_goals_coverage.ts

24 行, 1.3 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // QLT-R09 (observe). A sensor, not a check: lists the goals (layer "Business", type Goal) that have no benefit in
  2. // operation (an Outcome with `goal` on them) or no indicator of potential (an Indicator whose `outcomes` names one
  3. // of those benefits). Prints one line per goal with a gap and always exits 0: the norm only observes.
  4. import { Project } from '../../collections/checks/lib/speclib.ts';
  5. import { addr, fld, refs } from './lib/qlib.ts';
  6. export function gaps(p: Project): string[] {
  7. if (!p.coll('GOAL')) return [];
  8. const fGoal = fld(p, 'OUT', 'GOAL', 'goal');
  9. const fOut = fld(p, 'IND', 'OUT', 'outcomes');
  10. const out: string[] = [];
  11. for (const g of p.records('GOAL')) {
  12. const outs = p.records('OUT').filter((o) => refs(p, o, fGoal, 'GOAL').includes(g.id)).map((o) => o.id);
  13. const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && refs(p, i, fOut, 'OUT').some((x) => outs.includes(x)));
  14. const lack = [!outs.length && 'benefit in operation', !inds.length && 'indicator of potential'].filter(Boolean);
  15. if (lack.length) out.push(`${addr(g.id)}: the goal has no ${lack.join(' and ')}`);
  16. }
  17. return out;
  18. }
  19. if (import.meta.main) {
  20. const lines = gaps(new Project(process.cwd()));
  21. console.log(lines.length ? lines.join('\n') : 'every goal has a benefit and an indicator (or there are no goals)');
  22. }