forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: convert stylelint rules to typescript (angular#19047)
Converts the Stylelint rules to TypeScript so they're in line with the rest of the project and to make it easier to work with the PostCSS AST.
- Loading branch information
Showing
11 changed files
with
636 additions
and
438 deletions.
There are no files selected for viewing
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,11 @@ | ||
const path = require('path'); | ||
const stylelint = require('stylelint'); | ||
|
||
// Custom rule that registers all of the custom rules, written in TypeScript, with ts-node. This is | ||
// necessary, because `stylelint` and IDEs won't execute any rules that aren't in a .js file. | ||
require('ts-node').register({ | ||
project: path.join(__dirname, '../gulp/tsconfig.json') | ||
}); | ||
|
||
// Dummy rule so Stylelint doesn't complain that there aren't rules in the file. | ||
module.exports = stylelint.createPlugin('material/loader', () => {}); |
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
69 changes: 34 additions & 35 deletions
69
tools/stylelint/no-nested-mixin.js → tools/stylelint/no-nested-mixin.ts
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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
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; | ||
import {createPlugin, utils} from 'stylelint'; | ||
|
||
const ruleName = 'material/no-nested-mixin'; | ||
const messages = utils.ruleMessages(ruleName, { | ||
expected: () => 'Nested mixins are not allowed.', | ||
}); | ||
|
||
/** | ||
* Stylelint plugin that prevents nesting Sass mixins. | ||
*/ | ||
const plugin = createPlugin(ruleName, (isEnabled: boolean) => { | ||
return (root, result) => { | ||
if (!isEnabled) { return; } | ||
|
||
root.walkAtRules(rule => { | ||
if (rule.name !== 'mixin') { return; } | ||
|
||
rule.walkAtRules(childRule => { | ||
if (childRule.name !== 'mixin') { return; } | ||
|
||
utils.report({ | ||
result, | ||
ruleName, | ||
message: messages.expected(), | ||
node: childRule | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); | ||
|
||
plugin.ruleName = ruleName; | ||
plugin.messages = messages; | ||
export default 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
Oops, something went wrong.