Latest Tweet

Linting JavaScript in Sublime Text

Posted by Nate on May 29, 2012

I spent too much of my morning looking around for a good “linting” plugin for Sublime Text 2, so I figured I might share my findings. As a quick side note, we’ve pretty much all switched over to Sublime Text 2 here at BaM because it’s cross-platform (we’ve got devs on Macs and PCs) and has a ton of nice features like package control (via a plugin), introspection, code-collapsing, etc.

I was really looking specifically for something to run JSLint against my code as I save my files. As a bonus, I really wanted something that used node.js to run JSLint since that would again be a nice, cross-platform solution. After trying out a handful of Sublime/JSLint plugins, I landed on Sublime Linter. This is a fork of another plugin, but comes with a few more options and features than the original. It’s also supports more languages than just JavaScript. I’ve yet to try the other languages, but I’ll probably end up using the CSS and PHP linters. There’s also another fork of this project with an HTML linter using tidy-html5 waiting to be pulled.

Installation and Setup

I used the Package Control plugin to install (hit Command+Shift+P on OS X, Control+Shift+P on Linux/Windows to launch). It was a quick and painless install, but to get what I wanted, I had to tweak a few of the settings.

I switched the default JavaScript linter to JSLint (it defaults to JSHint). JSHint may be a fine linter too, but I haven’t had time to check it out yet.

"javascript_linter": "jslint", 

I also changed the linter to run on each save.

"sublimelinter_popup_errors_on_save": true, 

To get to the settings, navigate to Preferences->Package Settings->SublimeLinter->Settings - Default.

Make sure to check out the README for the plugin. It has a ton of other great features like per-project settings and the ability to create new linters.

Let us know if this works out for you or if you come across any better solutions.