2.2.1 • Published 2 months ago

stylelint-no-restricted-syntax v2.2.1

Weekly downloads
373
License
MIT
Repository
github
Last release
2 months ago

stylelint-no-restricted-syntax

Build Status

Stylelint rule to disallow specified syntax, similar to ESLint no-restricted-syntax.

Install

npm install stylelint-no-restricted-syntax --save

Usage

Add this config to your .stylelintrc:

{
	"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:

module.exports = {
	'plugins': ['stylelint-no-restricted-syntax'],
	'rules': {
		'plugin/no-restricted-syntax': [
			[
				{
					'selector': "decl[prop='z-index']",
					'message': (node) => `${node.prop} not allowed.`
				}
			]
		]
	}
};

Options

Each restricted syntax rule consists of the following properties:

PropertyTypeDescription
selectorstringSelector for querying PostCSS AST.
messagestring\|functionError message for queried PostCSS node. If using a function, the provided argument is the full PostCSS node.

Details

a {
	z-index: 10;
}
/**          ↑
 * Previous line will be considered as restricted syntax */
b {
	font-weight: bold;
}

License

MIT © Ivan Nikolić