How to disable the warning 'define' is not

2019-01-07 05:28发布

I uses RequireJS AMD in my project. When i run jshint on my project, it throws error like

In AMD Scripts

 'define' is not defined.

In Mocha test cases

 'describe' is not defined.
 'it' is not defined.

How to remove this warning in jshint?

8条回答
叛逆
2楼-- · 2019-01-07 05:36

To avoid the not defined warning in jshint for the javascript add comments like:

/*global describe:true*/

Options

查看更多
beautiful°
3楼-- · 2019-01-07 05:40

Add this in your .jshintrc

"predef" : ["define"]   // Custom globals for requirejs
查看更多
老娘就宠你
4楼-- · 2019-01-07 05:40

If you're trying to run JSHint in WebStorm with Mocha, as I am, go into:

WebStorm > Preferences > Languages & Frameworks > JavaScript > Code Quality Tools > JSHint

Scroll down to "Environments" and make sure you have selected the checkbox to enable "Mocha" which will set up the definitions for JSHint for Mocha for you.

查看更多
Emotional °昔
5楼-- · 2019-01-07 05:41

late to the party, but use this option in your jshintrc:

"dojo": true

and thou shall rest peacefully without red warnings...

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-07 05:54
jshint: {
  options: {
    mocha: true,
  }
}

is what you want

查看更多
三岁会撩人
7楼-- · 2019-01-07 05:56

Read the docs and search for /*global

查看更多
登录 后发表回答