Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stylelint-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"plugins": [
"./tools/stylelint/no-prefixes/no-prefixes.js",
"./tools/stylelint/selector-nested-pattern-scoped/index.js",
"./tools/stylelint/selector-no-deep/index.js"
"./tools/stylelint/selector-no-deep/index.js",
"./tools/stylelint/no-nested-mixin/index.js"
],
"rules": {
"material/no-prefixes": [["last 2 versions", "not ie <= 10", "not ie_mob <= 10"]],
"material/selector-no-deep": true,
"material/no-nested-mixin": true,
"material/selector-nested-pattern-scoped": [".*[^&]$", {
"message": "The & operator is not allowed at the end of theme selectors.",
"filePattern": "-theme\\.scss$"
Expand Down
35 changes: 35 additions & 0 deletions tools/stylelint/no-nested-mixin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const stylelint = require('stylelint');

const ruleName = 'material/no-nested-mixin';
const messages = stylelint.utils.ruleMessages(ruleName, {
expected: () => 'Nested mixins are not allowed.',
});


/**
* Stylelint plugin that prevents nesting SASS mixins.
*/
const plugin = stylelint.createPlugin(ruleName, isEnabled => {
return (root, result) => {
if (!isEnabled) return;

root.walkAtRules(rule => {
if (rule.name !== 'mixin') return;

rule.walkAtRules(childRule => {
if (childRule.name !== 'mixin') return;

stylelint.utils.report({
result,
ruleName,
message: messages.expected(),
node: childRule
});
});
});
};
});

plugin.ruleName = ruleName;
plugin.messages = messages;
module.exports = plugin;