My Journey

I first learned about Stylelint while browsing through Styled Components documentation. I wasn’t specifically looking for it but since I had just setup ESLint and Prettier in my codebase, I was intrigued. From there, I started researching Stylelint. Pretty soon, I realized that while I had the ultimate Javascript linting setup through ESLint and Prettier, I had absolutely nothing for CSS. It was clear that this was my next task.

Stylelint

Stylelint is CSS’s linter. It works by analyzing your CSS and warning you if any configured rules are violated. These rules can catch CSS errors and enforce styling conventions. It’s similar to Google Doc’s or Microsoft Word’s spelling and grammar checking — essentially an automatic proofreader for your CSS!

Configuration

Stylelint runs off a configuration file named stylelint.config.js. This configuration file is broken down into rulesplugins, and extensions.

Rules

Rules define what Stylelint will look for in your code. These are defined in the rules section of the configuration as key value pairs. The key is the rule and the value toggles the rule and sets the options.

Enabling a rule depends on the rule itself — some rules it could be as simple as setting the value to true; others have the ability to tune directly via a keyword.

// stylelint.config.js
module.exports = {
  rules: {
    'declaration-no-important': true,
    'color-hex-case': 'upper',
  },
};

Some rules also allow you to customize it even further with additional configuration options. In this case, the primary option and the additional configurations are an array.

#javascript #eslint #code-quality #stylelint #web-development

Stylelint — The CSS Cousin of ESLint
1.35 GEEK