-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (25 loc) · 970 Bytes
/
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
const stylelint = require('stylelint');
const ruleName = 'pitcher/max-lines';
const messages = stylelint.utils.ruleMessages(ruleName, {
expected: (maxLines, countLines) => [
`Expected no more than ${maxLines} lines.`,
`Found ${countLines} lines.`,
].join(' '),
});
module.exports = stylelint.createPlugin(ruleName, (maxLines) => ((postcssRoot, postcssResult) => {
const validOptions = stylelint.utils.validateOptions(postcssResult, ruleName, {
actual: maxLines,
possible: Number.isInteger,
});
if (!validOptions) return undefined;
const countLines = postcssRoot.source.input.css.split(/\r\n|\n/).length;
if (countLines <= maxLines) return undefined;
return stylelint.utils.report({
message: messages.expected(maxLines, countLines),
node: postcssRoot,
result: postcssResult,
ruleName,
});
}));
module.exports.ruleName = ruleName;
module.exports.messages = messages;