How to tell JSLint / JSHint what global variables are already defined

女生的网名这么多〃 提交于 2019-12-17 17:42:30

问题


In my project we have some global variables that work as containers:

MyProject.MyFreature.someFunction = function() { ... }

So then I use that script across the site and JSLint / JSHint complains about that:

'MyProject' is not defined

I know that I can go to every JavaScript file and add the comment /*global MyProject*/ on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment.

Some kind on option in the config/jshint.yml would be nice.


回答1:


For JSHint you can create .jshintrc to your project directory with

{
  "globals": { "MyProject": true }
}



回答2:


This is only for globals

/* global MyProject */

In your case you need

/* exported MyProject */



回答3:


JSLint has a textarea below the options that says predefine global variables here in it. Just add the variable names in there before running the check.

JSHint doesn't allow you to add global variables, but you can uncheck the When variable is undefined option to suppress that warning.

The JSHint library also has parameters for globals, if you run it as a library . . . details in here: http://jshint.com/docs/



来源:https://stackoverflow.com/questions/17709657/how-to-tell-jslint-jshint-what-global-variables-are-already-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!