-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (34 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const stylelint = require("stylelint");
const ruleName = "aditayvm/at-rule-no-children";
const messages = stylelint.utils.ruleMessages(ruleName, ({
unexpected: (block, rule) => `Unexpected rule "${block}" inside at-rule "${rule}".`,
}));
module.exports = stylelint.createPlugin(ruleName, function(options = "") {
return function(root, result) {
var validOptions = stylelint.utils.validateOptions({
ruleName: ruleName,
result: result,
actual: options,
});
if (!validOptions) {
return;
}
const params = new RegExp(`(${((options || {}).ignore || []).join("|")})\\\(`);
root.walkAtRules(function(statement) {
(statement.nodes || []).forEach(node => {
if ((options || {}).ignore) { // ignore list
if (options.ignore.includes(node.parent.name)) return; // @foo
if (params.test(node.parent.params)) return; // @include foo
}
if (node.type !== "rule") return; // allow non-rules
if (node.selector.match(/^[^.#]?(\d+%|from|to)/)) return; // allow 90% / from / to
stylelint.utils.report({
ruleName,
result,
node,
message: messages.unexpected(node.selector, statement.name),
});
});
});
};
});