Stylelint — The CSS Cousin of ESLint

Stylelint — The CSS Cousin of ESLint

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.

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

13 Useful JavaScript Developer Tools for Writing High-Quality Code

Today I’m going to show you 13 well-know and popular tools to write better and cleaner JavaScript code. These are tools that I’m using right now on my JavaScript developer journey. So if you want to improve the quality of your projects, this list is for you.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

ESLint — A Proofreader for your Code

ESLint is Javascript’s linter. It works by analyzing your code and warning you if any configured rules are violated. These rules can detect suspicious or concerning coding quality or formatting issues.

Hire Dedicated eCommerce Web Developers | Top eCommerce Web Designers

Build your eCommerce project by hiring our expert eCommerce Website developers. Our Dedicated Web Designers develop powerful & robust website in a short span of time.