I have a front-end build for which I am setting up style linting. The project is using Stylelint. At the moment, there are a bunch of warnings, which I need to address. It appears that some of them are such that I can easily allow the linter to fix them right now. The other ones I would like to take a look at more carefully.
My question is whether it is possible to run the fix such that it applies only one rule and ignores everything else. For example, suppose there is a rule that after a comma there must be a space character. Then, I would like the linter to fix all such occurrences and not touch anything else. How can I do that?
In package.json, I have the following commands:
"lint:styles": "stylelint \"src/**/*.scss\"",
"lint:styles --fix": "stylelint \"src/**/*.scss\" --syntax=scss --fix",
"lint:scripts": "eslint --color ./src/blocks",
"lint:scripts --fix": "eslint --fix --color ./src/blocks",
Some of the lint-related things I am using
"lint-staged": "^10.0.3",
"postcss": "^8.4.4",
"stylelint": "^14.1.0",
"stylelint-config-standard-scss": "^3.0.0",
"stylelint-order": "^4.1.0",
"stylelint-selector-bem-pattern": "^2.1.1",
The top of the .stylelintrc file looks as follows
{
"extends": ["stylelint-config-standard-scss"],
"customSyntax": "postcss-scss",
"plugins": [
"stylelint-order",
"stylelint-selector-bem-pattern"
],
"rules": {
...
It's not currently possible to apply autofix to a single rule while ignoring the other. (There is an open ticket to add options to allow this.)
It's clunky, but you can temporarily comment-out/remove all the rules except the one you want to autofix, run Stylelint, and then add the other rules back in. If you want to autofix a rule that's included in a shared config that you've extended, then you'll need to copy the rule config into your rules array. For example, here are the rules of the stylelint-config-standard-scss shared config.