stylelint-itcss
Version:
A stylelint plugin to help with itcss architecture
51 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const stylelint_1 = require("stylelint");
const validate_layer_1 = require("../../utils/validate-layer");
// import isStandardSyntaxRule from "stylelint/lib/utils/isStandardSyntaxRule";
exports.ruleName = "itcss/no-at-important";
exports.messages = stylelint_1.utils.ruleMessages(exports.ruleName, {
expected: `Use of "!important" is forbidden in this layers`,
});
function findAtImportant(node) {
if (node.type !== "rule") {
return null;
}
return node.nodes.filter(o => o.type === "decl" && o.important === true);
}
function rule(enable, options = {}) {
return (root, result) => {
// const validOptions = utils.validateOptions(result, ruleName, { enable }); // 🤷♂️
if (enable === false || validate_layer_1.isIgnoredLayer(options.ignoreLayers, result.opts.from)) {
return;
}
root.walk(node => {
let selector = node.selector;
// if (node.type === "rule") {
// if (!isStandardSyntaxRule(node)) {
// return;
// }
// selector = node.selector;
// } // else if (node.type === "atrule" && node.name.toLowerCase() === "page" && node.params) {
// selector = node.params;
// }
if (!selector) {
return;
}
const atImportantProperties = findAtImportant(node);
if (atImportantProperties !== null) {
atImportantProperties.forEach(property => {
stylelint_1.utils.report({
// index: node.lastEach,
message: exports.messages.expected,
node: property,
ruleName: exports.ruleName,
result
});
});
}
});
};
}
exports.default = rule;
//# sourceMappingURL=index.js.map