Stylelint rule to disallow specified syntax.
npm install stylelint-no-restricted-syntax[![Build Status][ci-img]][ci]
Stylelint rule to disallow specified syntax, similar to ESLintno-restricted-syntax.
``sh`
npm install stylelint-no-restricted-syntax --save
Add this config to your .stylelintrc:
`json`
{
"plugins": ["stylelint-no-restricted-syntax"],
"rules": {
"plugin/no-restricted-syntax": [
[
{
"selector": "rule[selector='a']",
"message": "Anchors not allowed."
},
{
"selector": "decl[prop='z-index']",
"message": "z-index not allowed."
}
]
]
}
}
If using a JavaScript config file (e.g., stylelint.config.cjs), you may also
use a function that returns a message:
`js${node.prop} not allowed.
module.exports = {
'plugins': ['stylelint-no-restricted-syntax'],
'rules': {
'plugin/no-restricted-syntax': [
[
{
'selector': "decl[prop='z-index']",
'message': (node) => `
}
]
]
}
};
Each restricted syntax rule consists of the following properties:
| Property | Type | Description |
| ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------ |
| selector | string | Selector for querying PostCSS AST. |message
| | string\|function | Error message for queried PostCSS node. If using a function, the provided argument is the full PostCSS node. |
`css``
a {
z-index: 10;
}
/** ↑
Previous line will be considered as restricted syntax /
b {
font-weight: bold;
}
MIT © Ivan Nikolić
[ci]: https://github.com/niksy/stylelint-no-restricted-syntax/actions?query=workflow%3ACI
[ci-img]: https://github.com/niksy/stylelint-no-restricted-syntax/workflows/CI/badge.svg?branch=master