10 CSS and JavaScript Linting Tools for Code Optimization

Linting tools can significantly help developers to write good quality, optimized code. Linting is a code-checking process that looks for errors in the source code, and flags potential bugs. Most linters use the static code analysis technique, which means the code is checked without being actually executed.

You can lint on different occassions, such as in real time while you write the code, when you save the file, when you commit the changes, or before the code goes into production. Whatever your workflow is like, the important thing is to lint on a regular basis, as it can save you from many headaches in the future.

Linters are not solely bug prevention tools, but they can also be effectively used during debugging to find errors that are hard to catch otherwise. In this post we will check out 10 powerful linting tools you can use to lint your CSS and JavaScript files in order to improve the quality of your code.

1. CSSLint

CSSLint admittedly intends to "hurt your feelings", but in exchange it "makes you code much better". CSSLint currently leads the market of CSS linting. It’s written in JavaScript, it’s open-source, and comes with tons of configurable options.

CSSLint allows you to choose what kind of errors and warnings (compatibility, performance, duplication, etc.) you want to test for, and validates your CSS syntax against the rules you opt for.

It doesn’t only work in the browser, but also has a command line interface, and you can integrate it into your own build system as well.

CSSLint

2. SublimeLinter CSSLint

CSSLint is such an effective CSS linter that it’s hard to find a competitor that measures up to it. Probably that’s the reason why the SublimeLinter linting framework built its CSS linting plugin on top of it. SublimeLinter is a SublimeText plugin that provides users with a means to lint their code (CSS, PHP, Python, Java, Ruby, etc.) right inside the SublimeText editor.

Before you install the SublimeLinter CSSLint plugin itself, you need to install CSSLint as a Node.js module. The great thing about this handy tool is that you only have to configure the settings once, or if you’re happy with the defaults you don’t even have to do that, then you can always get the relevant warnings and notifications inside your SublimeText editor without any further hassle.

SublimeLinter

3. StyleLint

StyleLint helps developers avoid errors in CSS, SCSS, or any other syntaxes that PostCSS can parse. StyleLint tests for over a hundred rules, and you can choose which ones you want to switch on (see an example config).

If you don’t want to build your own configuration, you can also opt for a pre-written, standard config that contains about 60 StyleLint rules. StyleLint is a quite flexible tool, it can be extended by extra plugins, and used in 3 different forms: as a command line tool, as a Node.js module, or as a PostCSS plugin.

StyleLint

4. W3C CSS Validator

Although W3C’s CSS Validator is usually not thought of as a linting tool, it gives developers a great opportunity to check their CSS source code against W3C’s official standards. W3C built its validators with the intent to provide a tool that’s similar to the Lint program checker for the C language.

At first, they created the HTML markup validator that was later followed by the CSS validator. W3C’s CSS validator doesn’t have as many options as CSSLint, but it returns detailed, easy-to-understand error messages and notifications.

As an extra feature, you can also check your code against W3C’s recent mobile web standards, which is not a bad thing in the era of the mobile web.

W3C CSS Validator

5. Dirty Markup

Dirty Markup cleans, formats, and validates your HTML, CSS, and JavaScript code. It can be a great choice if you like straightforward design and want a quick solution. Dirty Markup throws error messages and notifications in real time while you write or modify your code inside the editor.

When you hit the “Clean” button, it fixes syntax errors at once, tidies up the format, but leaves the warnings intact letting you solve them however you want. You can’t choose which rules you want to test for, but all three file types have a few settings that enable you to decide the format of the cleaned output.

Dirty Markup

6. JSLint

JSLint was first released in 2002 by Douglas Crockford, and haven’t lost momentum since then, so you can safely assume that it’s a stabile and reliable JavaScript linting tool.

JSLint can process JavaScript source code and JSON text, and it comes with a ready-made configuration that follows the JS best practices Crockford wrote about in his book entitled JavaScript: The Good Parts.

JSLint has a few options you can choose from, but you can’t add your own custom rules, or disable most of the features. JSLint has already begun to include the latest ECMAScript 6 standards, you can check out the current stage of the ES6 implementation here.

JSLint

7. JSHint

JSHint is a highly popular fork of JSLint, and it’s used by major tech companies like Facebook, Twitter, and Medium

JSHint is a community-driven project that started out with the endeavour to create a more configurable and less opinionated version of JSLint. JSHint allows developers to configure any of its linting options, and place the customized configuration into a separate file, an option that makes the tool easily reusable, and a good fit for bigger projects.

You not only can use JSHint to lint vanilla JavaScript, it also has out-of-the-box support for many popular JS libraries, such as jQuery, Mootools, Mocha, and Node.js.

JSHint

8. ESLint

ESLint is the latest big thing on the JavaScript linting landscape. Its popularity stems from its highly flexible nature. You not only can customize tons of its sophisticated linting rules, and integrate it with all major code editors, but you can also easily extend its functionalities by adding different plugins to it.

By specifying the parser options, you can also choose which standard of the JS language you want to support during the linting process, which means you not only can check your scripts against the default ECMAScript 5 syntax, but also against ECMAScript 6, ECMAScript 7, and JSX.

ESLint

9. JSCS

JSCS, or JavaScript Code Style is a pluggable code style linter for JavaScript, that checks for code formatting rules.

The goal of JSCS is to provide a means to programmatically enforce adherence to a certain coding style guide. Although JSCS doesn’t check bugs and errors, it’s still used by many major players in the tech industry, such as Google, AirBnB, and AngularJS, as it helps developers keep a highly readable, consistent code base.

JSCS is a real time-saver, as it automatically fixes your formatting errors, so you don’t have to go through them one by one. It has many different presets belonging to bigger projects, such as Google, Grunt, or Wikimedia coding style presets, that you can easily use in your own projects, but you can also create your own custom configuration.

JSCS

10. StandardJS

StandardJS, or JavaScript Standard Style is a code style linter just like JSCS, but differs from it in its simplicity and straightforwardness. StandardJS can be an excellent choice, if you don’t want to spend time with configuration, just want an effective tool that runs out of the box.

StandardJS follows a handful of pre-written formatting rules, and its core value is to keep your coding workflow distraction-free, so you can’t change the rules you disagree with. Only choose StandardJS if you don’t want to have a custom config, and just want to enforce a consistent code style across your JavaScript files.

StandardJS
WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail