-
Notifications
You must be signed in to change notification settings - Fork 115
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
d8a9f21
commit 2d1301c
Showing
2 changed files
with
50 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict" | ||
|
||
const astCheckerPlugin = () => { | ||
return { | ||
postcssPlugin: "ast-checker-plugin", | ||
OnceExit(root) { | ||
root.walkAtRules(node => { | ||
if (typeof node.params !== "string") { | ||
throw node.error( | ||
`Params must be of type 'string', found '${typeof node.params}' instead`, | ||
) | ||
} | ||
|
||
if (typeof node.type !== "string") { | ||
throw node.error( | ||
`Type must be of type 'string', found '${typeof node.type}' instead`, | ||
) | ||
} | ||
|
||
if (node.type !== "atrule") { | ||
throw node.error( | ||
`Type must be 'atrule', found '${node.type}' instead`, | ||
) | ||
} | ||
|
||
if (typeof node.name !== "string") { | ||
throw node.error( | ||
`Name must be of type 'string', found '${typeof node.name}' instead`, | ||
) | ||
} | ||
|
||
if (node.nodes && !Array.isArray(node.nodes)) { | ||
throw node.error( | ||
`Nodes must be of type 'Array' when it is present, found '${typeof node.nodes}' instead`, | ||
) | ||
} | ||
|
||
if (!("parent" in node)) { | ||
throw node.error("AtRule must have a 'parent' property") | ||
} | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
astCheckerPlugin.postcss = true | ||
|
||
module.exports = astCheckerPlugin |
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