-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle thrown errors of autofix function
- Loading branch information
Showing
5 changed files
with
128 additions
and
22 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
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,31 @@ | ||
// eslint-disable-next-line consistent-return, no-unused-vars, @typescript-eslint/no-unused-vars | ||
function autoFixFunc(node, validation, root, config) { | ||
const { value, prop } = node; | ||
|
||
if (prop === 'color') { | ||
// eslint-disable-next-line default-case | ||
switch (value) { | ||
case '#fff': | ||
// auto-fix by returned value | ||
return '$color-white'; | ||
|
||
case 'red': | ||
// auto-fix by PostCSS AST tranformation | ||
// eslint-disable-next-line no-param-reassign | ||
node.value = '$color-red'; | ||
// eslint-disable-next-line consistent-return | ||
return; | ||
|
||
default: | ||
// eslint-disable-next-line @typescript-eslint/no-throw-literal | ||
throw `Can't fix color "${value}"`; | ||
} | ||
} else if (prop === 'font-size') { | ||
throw new Error(`"${prop}" is not a color property`); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-throw-literal | ||
throw null; | ||
} | ||
|
||
module.exports = autoFixFunc; |