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_STRING = 'core/valid-string'; const ERROR = 'ERROR'; const rule = { meta: { messages: { [ERROR]: 'Must be a string.', }, docs: { description: 'Require string tokens to follow the Terrazzo extension.', url: docsLink(VALID_STRING), }, }, defaultOptions: {}, create({ tokens, report }) { for (const t of Object.values(tokens)) { if (t.aliasOf || !t.originalValue || t.$type !== 'string') { continue; } validateString(t.originalValue.$value, { node: getObjMember(t.source.node, '$value'), filename: t.source.filename, report, }); } }, }; function validateString(value, { node, filename, report, }) { if (typeof value !== 'string') { report({ messageId: ERROR, node, filename }); } } export default rule; //# sourceMappingURL=valid-string.js.map