Categories: Portfolio, Software Development, Web Dev Training

Stylelint: Lint your CSS

When working with CSS, developers usually don’t think about running a linter on the stylesheets. We usually use linters on C or C++ or JavaScript codebases. However, we don’t often think about whether or not it’s even possible to lint a CSS stylesheet and enforce certain coding standards and rules on it.

With Stylelint, you can lint your CSS and make sure it’s in line with common standards, more powerful than that is writing your own stylelint rules.

CSS Needs Linting Tools Just Like Other Languages

Here’s a few reasons why you would want to write your own custom rules for a linting tool:

  • You can make sure the code base is readable and consistent (a necessity for CSS!)
  • You can prevent some mistakes from happening (for example, always using parens around method calls in Ruby or CoffeeScript, or making sure every method has a comment explaining what it does)
  • Linters can warn you of potential issues (to take a Ruby on Rails or Django example, when you’re using the wrong method to get the count of items in the database)

So I sat down and read through the CSS stylelint guide on writing plugins and rules and came up with a basic example that other developers can build upon to lint their own CSS code.

Continue reading “Stylelint: Lint your CSS”