ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/norms-core/checks/levels.ts

checks/levels.ts

25 líneas, 1.1 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // NS-R01. The level of a rule or a principle is MUST, SHOULD or MAY; a default's level, when set, is SHOULD.
  2. import { empty, main, records } from './pagelib.ts';
  3. import { pystr } from '../../collections/checks/lib/pages.ts';
  4. const WORDS = ['MUST', 'SHOULD', 'MAY'];
  5. export const RULE = { id: 'ns-r01', title: 'Norm strength is one of the words MUST, SHOULD, MAY' };
  6. export function check(): string[] {
  7. const out: string[] = [];
  8. for (const folder of ['norms/rules', 'norms/principles']) {
  9. for (const [addr, head] of records(folder)) {
  10. const level = head.level;
  11. if (folder === 'norms/rules' && empty(level)) out.push(`${addr}: no level field — MUST, SHOULD or MAY is needed`);
  12. else if (!empty(level) && !WORDS.includes(pystr(level).trim())) out.push(`${addr}: level "${pystr(level)}" — MUST, SHOULD or MAY is needed`);
  13. }
  14. }
  15. for (const [addr, head] of records('norms/defaults')) {
  16. const level = head.level;
  17. if (!empty(level) && pystr(level).trim() !== 'SHOULD') out.push(`${addr}: a default has level "${pystr(level)}" — SHOULD is needed`);
  18. }
  19. return out;
  20. }
  21. if (import.meta.main) main({ RULE, check });