-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1.02 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
const stylelint = require("stylelint");
var path = require("path");
const ruleName = "filenames/match-regex";
const messages = stylelint.utils.ruleMessages(ruleName, {
expected: "Expected ..."
});
module.exports = stylelint.createPlugin(
ruleName,
function (primaryOption, secondaryOptionObject) {
return function (postcssRoot, postcssResult) {
var dRegexp = /^[a-z_A-Z0-9]$/g,//default
cRegexp = secondaryOptionObject ? new RegExp(secondaryOptionObject) : dRegexp;
var filename = postcssRoot.source.input.from,
extfile = path.extname(filename),
name = path.basename(filename),
matchRegex = cRegexp.test(name);
if (!matchRegex) {
stylelint.utils.report({
message: "Filename "+ name + " does not match the regex expression.",
ruleName: ruleName,
result: postcssResult,
line: 1,
column: 1
});
}
};
}
);
module.exports.ruleName = ruleName;
module.exports.messages = messages;