@lyliya/stylelint-value-no-unknown-custom-properties
Version:
A stylelint rule to disallow usage of unknown custom properties
19 lines (14 loc) • 542 B
JavaScript
import validateDecl from './validate-decl.mjs';
// validate the css root
export default (result, customProperties) => {
// validate each declaration
result.root.walkDecls(decl => {
if (hasCustomPropertyReference(decl)) {
validateDecl(decl, { result, customProperties });
}
});
};
// match custom property inclusions
const customPropertyReferenceRegExp = /(^|[^\w-])var\([\W\w]+\)/i;
// whether a declaration references a custom property
const hasCustomPropertyReference = decl => customPropertyReferenceRegExp.test(decl.value);