Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29807c2
commit f29ed19
Showing
12 changed files
with
198 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const stylelint = require('stylelint'); | ||
|
||
const ruleName = 'bitbank/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const stylelint = require('stylelint'); | ||
const path = require('path'); | ||
const isStandardSyntaxRule = require('stylelint/lib/utils/isStandardSyntaxRule'); | ||
const isStandardSyntaxSelector = require('stylelint/lib/utils/isStandardSyntaxSelector'); | ||
|
||
const ruleName = 'bitbank/selector-nested-pattern-scoped'; | ||
const messages = stylelint.utils.ruleMessages(ruleName, { | ||
expected: selector => `Expected nested selector '${selector}' to match specified pattern`, | ||
}); | ||
|
||
/** | ||
* Re-implementation of the `selector-nested-pattern` Stylelint rule, allowing us | ||
* to scope it to a particular set of files via the custom `filePattern` option. The | ||
* primary use-case is to be able to apply the rule only to theme files. | ||
* | ||
* Reference: https://stylelint.io/user-guide/rules/selector-nested-pattern/ | ||
* Source: https://github.com/stylelint/stylelint/blob/master/lib/rules/selector-nested-pattern/ | ||
*/ | ||
const plugin = stylelint.createPlugin(ruleName, (pattern, options) => { | ||
return (root, result) => { | ||
const selectorPattern = new RegExp(pattern); | ||
const filePattern = new RegExp(options.filePattern); | ||
const fileName = path.basename(root.source.input.file); | ||
|
||
if (!filePattern.test(fileName)) return; | ||
|
||
root.walkRules(rule => { | ||
if (rule.parent.type === 'rule' && | ||
isStandardSyntaxRule(rule) && | ||
isStandardSyntaxSelector(rule.selector) && | ||
!selectorPattern.test(rule.selector)) { | ||
|
||
stylelint.utils.report({ | ||
result, | ||
ruleName, | ||
message: messages.expected(rule.selector), | ||
node: rule | ||
}); | ||
} | ||
}); | ||
}; | ||
}); | ||
|
||
plugin.ruleName = ruleName; | ||
plugin.messages = messages; | ||
module.exports = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const stylelint = require('stylelint'); | ||
const isStandardSyntaxRule = require('stylelint/lib/utils/isStandardSyntaxRule'); | ||
const isStandardSyntaxSelector = require('stylelint/lib/utils/isStandardSyntaxSelector'); | ||
|
||
const ruleName = 'bitbank/selector-no-deep'; | ||
const messages = stylelint.utils.ruleMessages(ruleName, { | ||
expected: selector => `Usage of the /deep/ in "${selector}" is not allowed`, | ||
}); | ||
|
||
|
||
/** | ||
* Stylelint plugin that prevents uses of /deep/ in selectors. | ||
*/ | ||
const plugin = stylelint.createPlugin(ruleName, isEnabled => { | ||
return (root, result) => { | ||
if (!isEnabled) return; | ||
|
||
root.walkRules(rule => { | ||
if (rule.parent.type === 'rule' && | ||
isStandardSyntaxRule(rule) && | ||
isStandardSyntaxSelector(rule.selector) && | ||
rule.selector.includes('/deep/')) { | ||
|
||
stylelint.utils.report({ | ||
result, | ||
ruleName, | ||
message: messages.expected(rule.selector), | ||
node: rule | ||
}); | ||
} | ||
}); | ||
}; | ||
}); | ||
|
||
plugin.ruleName = ruleName; | ||
plugin.messages = messages; | ||
module.exports = plugin; |