Editor Integration and Auto-Fix
You'll learn how to set up Stylelint in your code editor and configure automatic fixes to save time and maintain consistency effortlessly.
Why Editor Integration Matters
Imagine having a helpful assistant who quietly corrects your spelling as you type, rather than waiting until you submit an essay to discover mistakes. That's what editor integration does for your CSS—it highlights issues in real-time and can even fix them automatically when you save.
Setting Up Stylelint in VS Code
First, install the Stylelint extension from the VS Code marketplace. Search for "Stylelint" by the Stylelint team and install it.
Next, ensure VS Code recognizes your configuration file (.stylelintrc.json or similar) in your project root. The extension will automatically detect it and start underlining issues in your CSS files.
Enabling Auto-Fix on Save
Open your VS Code settings (JSON format) and add:
{
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
},
"stylelint.validate": ["css", "scss", "sass", "less"]
}
Now, whenever you save a CSS file, Stylelint automatically fixes problems it can resolve—indentation, spacing, quote styles, and more.
Using the --fix CLI Flag
For batch fixes or CI/CD pipelines, run Stylelint with the --fix flag in your terminal:
npx stylelint "**/*.css" --fix
This scans all CSS files and applies automatic corrections where possible, just like the editor does on save.
Key Takeaway: Editor integration with auto-fix on save provides instant feedback and corrections as you write CSS, while the --fix CLI flag handles batch repairs—both keep your codebase clean with minimal manual effort.