I ‘m a big fan of JS Lint and as a front end web developer I need a linter to help me validate and maintain my code quality against best practices so I can use the language the way it was intended to use, and maintain form. When it comes to editors I use the popluar Sublime Text 2 as my default editor (as many web developers do these days). Luckily integrating JS Lint by Crockford in Sublime Text 2 is a breeze.
Just follow the steps below:
- Obviously, you need to install Sublime Text 2. It’s lightweight, cross platform and performs like an athlete on steroids-blazing fast.
- Using the console, install Sublime Package Control. Paste in the following commands:
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')
While the package is installing you should see installing [ = ] loader on the bottom left. Then all you have to do is to restart Sublime Text 2.
- Next. Goto: Projects > Package Control > Install Packages and type in “JS Lint”. You’ll immediately see a list of packages you can install. You’ll also notice that another version js lint with node.js. You may also prefer JS Hint. To get to package control in your Mac: CMD + Shift + P ==> Win, Linux users: try these shortcuts
// there are others as well, such as white space
// if you don't prefer Crockford's whitespace usage.
// this is to run jslint on save
// debug flag.
Now on save you should have your linter below where the console pops up:
If you run into problems with the console you can perform manual steps to install package control. Of course for the curious there is are a slew of packages / plugins out there, so go ahead and enjoy playing around with this lovely text editor.