/
index.js
82 lines (70 loc) · 2.09 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const stylelint = require('stylelint');
const { getContainingNode, isRuleWithNodes } = require('../../utils');
const { isNumber } = require('../../utils/validateType');
const checkNodeForOrder = require('./checkNodeForOrder');
const checkNodeForEmptyLines = require('./checkNodeForEmptyLines');
const createOrderInfo = require('./createOrderInfo');
const validatePrimaryOption = require('./validatePrimaryOption');
const ruleName = require('./ruleName');
const messages = require('./messages');
function rule(primaryOption, options = {}, context = {}) {
return function ruleBody(root, result) {
let validOptions = stylelint.utils.validateOptions(
result,
ruleName,
{
actual: primaryOption,
possible: validatePrimaryOption,
},
{
actual: options,
possible: {
unspecified: ['top', 'bottom', 'ignore', 'bottomAlphabetical'],
emptyLineBeforeUnspecified: ['always', 'never', 'threshold'],
emptyLineMinimumPropertyThreshold: isNumber,
},
optional: true,
},
);
if (!validOptions) {
return;
}
let isFixEnabled = context.fix;
let expectedOrder = createOrderInfo(primaryOption);
let processedParents = [];
// Check all rules and at-rules recursively
root.walk(function processRulesAndAtrules(input) {
let node = getContainingNode(input);
// Avoid warnings duplication, caused by interfering in `root.walk()` algorigthm with `getContainingNode()`
if (processedParents.includes(node)) {
return;
}
processedParents.push(node);
if (isRuleWithNodes(node)) {
checkNodeForOrder({
node,
isFixEnabled,
primaryOption,
unspecified: options.unspecified || 'ignore',
result,
expectedOrder,
});
checkNodeForEmptyLines({
node,
context,
emptyLineBeforeUnspecified: options.emptyLineBeforeUnspecified,
emptyLineMinimumPropertyThreshold:
options.emptyLineMinimumPropertyThreshold || 0,
expectedOrder,
isFixEnabled,
primaryOption,
result,
});
}
});
};
}
rule.primaryOptionArray = true;
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;