UNPKG

stylelint-itcss

Version:
39 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stylelint_1 = require("stylelint"); const validate_layer_1 = require("../../utils/validate-layer"); exports.ruleName = "itcss/no-variable-declaration"; exports.messages = stylelint_1.utils.ruleMessages(exports.ruleName, { expected: `Creation of a variable is forbidden in this layers`, }); function check(node) { return node.prop.slice(0, 2) === "--" || node.prop.slice(0, 1) === "$" || node.prop.slice(0, 1) === "@"; } function checkIgnoredVariables(variable, ignoreVariables = []) { return ignoreVariables.indexOf(variable) !== -1; } function rule(enable, options = {}) { return (root, result) => { if (enable === false || validate_layer_1.isIgnoredLayer(options.ignoreLayers, result.opts.from)) { return; } root.walk(node => { const isDeclaration = node.type === "decl"; if (!isDeclaration) { return; } const isVariableDeclaration = check(node); const isIgnoredVariable = checkIgnoredVariables(node.prop, options.ignoreVariables); if (isVariableDeclaration === true && isIgnoredVariable === false) { stylelint_1.utils.report({ message: exports.messages.expected, node, ruleName: exports.ruleName, result }); } }); }; } exports.default = rule; //# sourceMappingURL=index.js.map