-
Notifications
You must be signed in to change notification settings - Fork 11
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
6623276
commit 05c830a
Showing
6 changed files
with
1,096 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.js |
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 @@ | ||
{ | ||
"extends": ["stylelint-config-standard-scss"], | ||
"plugins": [ | ||
"./custom-rules/hex-lowercase.js", | ||
"stylelint-order" | ||
], | ||
"rules": { | ||
"custom-rules/hex-lowercase": true, | ||
"order/properties-alphabetical-order": true | ||
} | ||
} |
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,59 @@ | ||
/* eslint-disable-next-line */ | ||
const stylelint = require('stylelint'); | ||
|
||
// pulled from | ||
// https://medium.com/swlh/writing-your-first-custom-stylelint-rule-a9620bb2fb73 | ||
const { report, ruleMessages, validateOptions } = stylelint.utils; | ||
|
||
const ruleName = 'custom-rules/hex-lowercase'; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
expected: (unfixed, fixed) => `Expected "${unfixed}" to be "${fixed}"` | ||
}); | ||
|
||
module.exports = stylelint.createPlugin( | ||
ruleName, | ||
(primaryOption, secondaryOptionObject, context) => | ||
function lint(postcssRoot, postcssResult) { | ||
const validOptions = validateOptions(postcssResult, ruleName, { | ||
// no options for now... | ||
}); | ||
|
||
if (!validOptions) { | ||
return; | ||
} | ||
|
||
const isAutoFixing = Boolean(context.fix); | ||
postcssRoot.walkDecls((decl) => { | ||
const hasCapitalLetters = | ||
/^#([A-F0-9]{6}|[A-F0-9]{3})$/.test(decl.value) && | ||
/[A-Z]/.test(decl.value); | ||
|
||
if (!hasCapitalLetters) { | ||
return; | ||
} | ||
|
||
const { value } = decl; | ||
const newValue = value.toLowerCase(); | ||
|
||
if (isAutoFixing) { | ||
if (decl.raws.value) { | ||
decl.raws.value.raw = newValue; | ||
} else { | ||
decl.value = newValue; | ||
} | ||
} else { | ||
report({ | ||
ruleName, | ||
result: postcssResult, | ||
message: messages.expected(value, newValue), | ||
node: decl, | ||
word: value | ||
}); | ||
} | ||
}); | ||
} | ||
); | ||
|
||
module.exports.ruleName = ruleName; | ||
module.exports.messages = messages; |
Oops, something went wrong.