UNPKG

@terrazzo/parser

Version:

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

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