Beginner's questions about JSHint and code inspections

Hello,

I am doing hobby project with Webstorm using javascript and node.js as languages. Because I am pretty new to js world, I would like to enforce good coding policies by using JSHint.

However I don't fully understand how should you configure JSHint and Inspections -settings in WebStorm.

What I have done:
- Enabled JSHint (Preferences -> Inspections -> Javascript -> Code quality tools -> JSHint)
- Configured JSHint (Preferences -> Javascript -> Code Quality Tools -> JSHint), checked Enable and Use config file, created .jshintrc using some basic JSHint settings found from JSHint github page.
- It is definetely enabled, because I see gazillion JSHint errors :^O

What I still don't understand:
- There are lots of settings in Webstorm under Preferences -> Inspections -> Javascript. Are they overlapping with JSHint or should I configure both JSHint and those settings?
- I have file debugger.js, where I have class named Debugger. JSHint complains that it is defined but never used. Yes, it is used from game.js, but not from debugger.js. How to configure JSHint that it would understand that something happens in different file?
- I use WADE as js game framework. I initialize wade.js in my index.html and then in game.js I just use wade.dosomething() etc etc. JSHint complains that wade is not defined, but game works ok. Should I somehow explicitly define wade in game.js.
- I understand that if you use JSHint or other code inspection tools, you should have 0 errors because otherwise you will treat following errors as "well, I can ignore this too...". However it seems to be quite impossible to reach 0 errors because .jshintrc itself seems to have problems, it is treated as JSON and have comments, which are not allowed in JSON. Should I remove comments (with license information) or is the best practice somehow exclude some of the files?

Thank you all for your help.

br,

Pasi

1 comment
Comment actions Permalink
- There are lots of settings in Webstorm under Preferences ->  Inspections -> Javascript. Are they overlapping with JSHint or should  I configure both JSHint and those settings?


They partially overlap. Whether to use both or either oif them is a matter of preferences

- I have file  debugger.js, where I have class named Debugger. JSHint complains that it  is defined but never used. Yes, it is used from game.js, but not from  debugger.js. How to configure JSHint that it would understand that  something happens in different file?


JSHint works on per-file basis and doesn't 'see' declarations/usages in other files. You need using 'exported' directive to suppress 'defined but never used' warnings for your global functions/variables:

exported

A directive for telling JSHint about global variables that are defined in the current file but used elsewhere

See also http://stackoverflow.com/questions/22037197/jshint-silence-variable-is-defined-but-never-used

- I use WADE as js game  framework. I initialize wade.js in my index.html and then in game.js I  just use wade.dosomething() etc etc. JSHint complains that wade is not  defined, but game works ok. Should I somehow explicitly define wade in  game.js.


Similar to above. You need to add such global symbols to globals list. Like

"globals": { "wade": false }

- I understand that if you use JSHint or other code  inspection tools, you should have 0 errors because otherwise you will  treat following errors as "well, I can ignore this too...". However it  seems to be quite impossible to reach 0 errors because .jshintrc itself  seems to have problems, it is treated as JSON and have comments, which  are not allowed in JSON. Should I remove comments (with license  information) or is the best practice somehow exclude some of the files?


I think, excluding certain file(s) from inspecting is a right choice



0

Please sign in to leave a comment.