-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 1.24 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
const stylelint = require('stylelint');
const ruleName = 'pitcher/no-nested-media';
const messages = stylelint.utils.ruleMessages(ruleName, {
error: (media) => [
`Partial support nested media queries: ${media}.`,
'[https://caniuse.com/#feat=mdn-css_at-rules_media_nested-queries]',
].join(' '),
});
module.exports = stylelint.createPlugin(ruleName, (actual) => ((postcssRoot, postcssResult) => {
const validOptions = stylelint.utils.validateOptions(postcssResult, ruleName, { actual });
if (!validOptions) return undefined;
return postcssRoot.walkAtRules(/^media$/i, (atRule) => {
const { parent } = atRule;
if (!parent) return undefined;
if (!(parent.type === 'atrule' && parent.name === 'media')) return undefined;
const source = atRule.source || parent.source;
const media = `@media (${parent.params}) { @media (${atRule.params}) { … } }`;
return stylelint.utils.report({
ruleName,
message: messages.error(media),
node: parent,
result: postcssResult,
line: source.start.line,
column: source.start.column,
});
});
}));
module.exports.ruleName = ruleName;
module.exports.messages = messages;