Easy Lint Check 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:
@lornajane Looks like http://t.co/DqJnRF32b2 has what you want. npm install -g esprima – you now have an "esvalidate" command.
— Glen Mailer (@glenathan) May 2, 2014
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!
Pingback: Easy Lint Check for JavaScript | Advanced PHP |...
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 :-)