UNPKG

@terrazzo/parser

Version:

Parser/validator for the Design Tokens Community Group (DTCG) standard.

35 lines 1.1 kB
import { getObjMember } from '@terrazzo/json-schema-tools'; import { docsLink } from '../lib/docs.js'; export const VALID_BOOLEAN = 'core/valid-boolean'; const ERROR = 'ERROR'; const rule = { meta: { messages: { [ERROR]: 'Must be a boolean.', }, docs: { description: 'Require boolean tokens to follow the Terrazzo extension.', url: docsLink(VALID_BOOLEAN), }, }, defaultOptions: {}, create({ tokens, report }) { for (const t of Object.values(tokens)) { if (t.aliasOf || !t.originalValue || t.$type !== 'boolean') { continue; } validateBoolean(t.originalValue.$value, { filename: t.source.filename, node: getObjMember(t.source.node, '$value'), report, }); } }, }; function validateBoolean(value, { node, filename, report, }) { if (typeof value !== 'boolean') { report({ messageId: ERROR, node, filename }); } } export default rule; //# sourceMappingURL=valid-boolean.js.map