JSHint across multiple files with inter dependencies

602 views
Skip to first unread message

Preetham Kajekar

unread,
Aug 11, 2014, 8:32:42 AM8/11/14
to jsh...@googlegroups.com
Hi,
 I think this has been asked multiple times, but still could not get it to work. 
 My app is defined across multiple files. For eg, there is utils.js , main.js. main.js uses functions defined in utils.js. 
 When I jshint main.js, it reports "xyz" is not defined. "xyz" is defined in utils.js ? 
 
 How do I get this to work ?

 I know about the globals options and I am using this for a whole lot of 3rd party libraries i am using. However, this is not an option since the actual code has multiple files with each file have lots of functions which are used elsewhere. So adding these functions/variables one by one to globals is not an option. 

 I tried invoking jshint <list of files>, but this too did not take care of dependencies ?

 Any help here will be appreciated ? 
 
Thanks,
 ~preetham 

Peter d

unread,
Aug 11, 2014, 10:28:43 AM8/11/14
to jsh...@googlegroups.com
What about declaring the global variables in the .jshintrc files in the `predef` array: http://www.jshint.com/docs/
You'd still have to add all the function names one by one, but only in a single place.

-peter

Preetham Kajekar

unread,
Aug 12, 2014, 12:41:47 AM8/12/14
to jsh...@googlegroups.com
This Peter for the response, but that still would not work too well. I am trying to lint code which has a lot of these problems - typos in function calls, mismatched number of args etc and trying to find a way to detect these problems. 
I am looking at ways to of finding that every function call is indeed defined, and is possible, even match the number of args between the declaration and the invocation. 
Adding all function names to the globals can be done with grep, but looking for something more fool proof. Any pointers on how I can add this to jshint ? If it works, would be happy to share it with the community. 


On Monday, August 11, 2014 7:58:43 PM UTC+5:30, Peter d wrote:. 

Peter d

unread,
Aug 12, 2014, 1:26:32 PM8/12/14
to jsh...@googlegroups.com
I'm not sure if you can do this in JSHint or ESLint easily (or even uneasily).
Finding out of the function call is defined should be easy, using the http://www.jshint.com/docs/options/#undef rule.

Finding mismatched number of arguments would be trickier, and possibly outside the scope of the linting tools (but I'd be happy if somebody has any ideas how to do it). I've done something similar in the past when I was trying to validate markdown code samples against the latest API but I was using Esprima, if I remember correctly. http://sevinf.github.io/blog/2012/09/29/esprima-tutorial/ may help you get started.

Good luck,
-peter
Reply all
Reply to author
Forward
0 new messages