0

Suppose I'm working with the javascript below:

var mapOptions = {
 zoom: 6
};
new google.maps.Map('#map', mapOption);

I've mistakenly passed mapOption instead of mapOptions. Is there a javascript linter that will pick up on this mistake? Either warning me that mapOption is undefined or that mapOptions is unused?

I would love to have this functionality with jshint and vim, but I'm not sure how to set it up.

Matt
  • 4,815
  • 5
  • 39
  • 40
  • 1
    Syntastic (https://github.com/scrooloose/syntastic) allows you to use jshint to lint javascript. List of supported linters: https://github.com/scrooloose/syntastic/wiki/Syntax-Checkers – EvergreenTree Feb 14 '15 at 17:39
  • 2
    `mapOption` could be defined in another file or at runtime so there is no error here. You can use jhint's `unused` option, though. You should look into code coverage tools instead like Istanbul or Blanket. – romainl Feb 14 '15 at 17:43
  • @EvergreenTree I have seen syntastic /jshint check for missing semicolons but not the error above. – Matt Feb 14 '15 at 17:45
  • @romainl ah, thanks for those tips! – Matt Feb 14 '15 at 17:46
  • You've lost me; that's exactly what JSLint does. JSLint would complain that, **"'mapOption' was used before it was defined."** if you linted that code, along with a complaint about using `google` without defining it, if you don't have a `global` directive, and that you're using `new` for side effects. **I think your question is, "How do I set up a linter with VIm?"**, and that's got [an answer here](http://stackoverflow.com/questions/473478/vim-jslint). Sound right? ;^) – ruffin Feb 17 '15 at 13:57

0 Answers0