-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (43 loc) · 1.16 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
// Abbreviated example
var stylelint = require('stylelint');
var ruleName = 'stylelint/regex';
var messages = stylelint.utils.ruleMessages(ruleName, {
expected: 'Expected ...'
});
module.exports = stylelint.createPlugin(ruleName, function(
primaryOption,
secondaryOptionObject
) {
return function(postcssRoot, postcssResult) {
var validOptions = stylelint.utils.validateOptions(
postcssResult,
ruleName,
primaryOption
);
if (!validOptions) {
return;
}
const fileName = postcssRoot.source.input.file;
const css = postcssRoot.source.input.css;
let m;
if (secondaryOptionObject.ignore.some(f => fileName.indexOf(f) > -1)) {
return;
}
primaryOption.forEach(o => {
for (regex in o) {
const message = o[regex];
m = new RegExp(regex, 'gm').exec(css);
if (m) {
stylelint.utils.report({
message: message + ' has been violated in ' + fileName,
ruleName: ruleName,
result: postcssResult,
node: postcssRoot
});
}
}
});
};
});
module.exports.ruleName = ruleName;
module.exports.messages = messages;