-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (43 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
53
54
var stylelint = require("stylelint");
var checkParents = require("./lib/check-parents");
var ruleName = "blinkist/no-repeated-nesting";
var messages = stylelint.utils.ruleMessages(ruleName, {
rejectedElements: "There can't be elements nested in elements",
rejectedModifiers: "There can't be modifiers nested in modifiers",
rejectedModifiersElements: "There can't be elements nested in modifiers"
});
module.exports = stylelint.createPlugin(ruleName, function(primaryOption, secondaryOptionObject) {
return function(postcssRoot, postcssResult) {
var validOptions = stylelint.utils.validateOptions(postcssResult, ruleName, {});
if (!validOptions) { return }
var parseTree = function(nodes) {
if (!nodes) {
return;
}
nodes.forEach(function(node) {
if (!node || !node.selector) {
return;
}
var tests = [
checkParents.elementsInElements(node),
checkParents.modifiersInModifiers(node),
checkParents.elementsInModifiers(node)
];
for (var i in tests) {
if (tests[i]) {
stylelint.utils.report({
message: messages[tests[i].messageKey],
ruleName: ruleName,
result: postcssResult,
node: tests[i].node,
});
}
}
parseTree(node.nodes);
});
}
parseTree(postcssRoot.nodes);
};
});
module.exports.ruleName = ruleName;
module.exports.messages = messages;