If you’re not using a JavaScript linter, you should be. There are a lot of great reasons to use a linter, to name a few:
- Improved code quality
- Less errors in your code
- Quickly spot common problems with JavaScript
- Less time debugging
Most modern code editors support linting in some form or another. For the purposes of this article I’ll show you how to quickly get setup in Sublime Text 3 using JSHint. The steps for ESLint are relatively the same.
- First make sure you have the Sublime Text package manager installed.
- Then make sure you have Node installed.
- While in Sublime Text you can press
Shift+Command P
to bring up your command palette. - Then type install and press enter.
- Type in
sublime-linter
and hit enter. This will install the sublime linter package. - Bring up the command palette again and type in
jshint
There should be a package calledsublimelinter-jshint
, hit enter to install it. - Open up your favorite terminal and type in
npm install -g jshint
- Restart Sublime Text and then open any JavaScript file and you should start to see yellow and red icons in your gutter denoting linting errors and warnings. If you don’t, you probably have pretty clean code!
If you have another linter you prefer such as eslint
feel free to install the packages for that.
Sample Lint Configuration
You can place this snippet in the root of your project and name it .jshintrc
to apply your own custom rules. Or you can modify your global jshint configuration in sublime text.
1 | { |