Easy Lint Check for JavaScript

I’m introducing lint checking on one of my projects, because it didn’t have a build process yet and I love this as a great place to start. Oh, and because we managed to commit broken syntax! So I set up a php lint job (I will share my travis config in another post) and tried to work out doing the same thing for JavaScript.

So it turns out that JSLint is really chatty and opinionated, and JSHint is almost as bad; I really only want to know if this JS is syntactically correct and I am not sure that I could care any less than this about whether the bracket or space characters are pleasing to the parser. I moaned on twitter (I know, shocking!) and got a few pointers – one really useful tip in particular:

On closer inspection this is a pretty nice set of tools for exactly what I wanted to do (and many other things besides). Even better, I found that there is a super-simple grunt task available to wrap Esprima and validate Javascript: grunt-jsvalidate. I don’t write much client-side JS but this does seem to be doing the trick on my project and it wasn’t as easy to find as I expected so I thought I’d mention it here in the hope that the next person searching for a simple way to check that their JavaScript is syntax-valid will find this rather than having to moan on twitter :)

If you’re using this or other tools, I’m interested to hear about it so please share in the comments!

2 thoughts on “Easy Lint Check for JavaScript

  1. Pingback: Easy Lint Check for JavaScript | Advanced PHP |...

  2. There are (good) reasons for JSHint/Lint complaining about syntactically valid code. I agree with most of those reasons and have little trouble adapting to their styles. I have my Vim setup so that JSHint complains as soon as I save a file so I can “correct” my code asap and when I’m working on it, not “way later” in my build process (using the Vim syntastic plugin).

    All that being said: linters are no shield against crappy code, you can write utter crap that is JSHint/Lint won’t have an opinion on. So keep using your head :-)

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.