@terrazzo/parser
Version:
Parser/validator for the Design Tokens Community Group (DTCG) standard.
46 lines • 1.69 kB
JavaScript
import { docsLink } from '../lib/docs.js';
import { cachedLintMatcher } from '../lib/matchers.js';
export const REQUIRED_TYPOGRAPHY_PROPERTIES = 'core/required-typography-properties';
/** @deprecated Use core/valid-typography instead */
const rule = {
meta: {
docs: {
description: 'Enforce typography tokens have required properties.',
url: docsLink(REQUIRED_TYPOGRAPHY_PROPERTIES),
},
},
defaultOptions: {
properties: ['fontFamily', 'fontSize', 'fontWeight', 'letterSpacing', 'lineHeight'],
},
create({ tokens, options, report }) {
if (!options) {
return;
}
if (options.properties.length === 0) {
throw new Error(`"properties" can’t be empty`);
}
const shouldIgnore = options.ignore ? cachedLintMatcher.tokenIDMatch(options.ignore) : null;
for (const t of Object.values(tokens)) {
if (shouldIgnore?.(t.id)) {
continue;
}
if (t.$type !== 'typography') {
continue;
}
if (t.aliasOf) {
continue;
}
for (const p of options.properties) {
if (!t.partialAliasOf?.[p] && !(p in t.$value)) {
report({
message: `This rule is deprecated. Use core/valid-typography. Missing required typographic property "${p}"`,
node: t.source.node,
filename: t.source.filename,
});
}
}
}
},
};
export default rule;
//# sourceMappingURL=required-typography-properties.js.map