包文件→ .shtukbase/packages/norms-core/checks/levels.ts
checks/levels.ts
25 行, 1.1 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // NS-R01. The level of a rule or a principle is MUST, SHOULD or MAY; a default's level, when set, is SHOULD.
- import { empty, main, records } from './pagelib.ts';
- import { pystr } from '../../collections/checks/lib/pages.ts';
- const WORDS = ['MUST', 'SHOULD', 'MAY'];
- export const RULE = { id: 'ns-r01', title: 'Norm strength is one of the words MUST, SHOULD, MAY' };
- export function check(): string[] {
- const out: string[] = [];
- for (const folder of ['norms/rules', 'norms/principles']) {
- for (const [addr, head] of records(folder)) {
- const level = head.level;
- if (folder === 'norms/rules' && empty(level)) out.push(`${addr}: no level field — MUST, SHOULD or MAY is needed`);
- else if (!empty(level) && !WORDS.includes(pystr(level).trim())) out.push(`${addr}: level "${pystr(level)}" — MUST, SHOULD or MAY is needed`);
- }
- }
- for (const [addr, head] of records('norms/defaults')) {
- const level = head.level;
- if (!empty(level) && pystr(level).trim() !== 'SHOULD') out.push(`${addr}: a default has level "${pystr(level)}" — SHOULD is needed`);
- }
- return out;
- }
- if (import.meta.main) main({ RULE, check });