How to disable the warning 'define' is not defined using JSHint and RequireJS

不羁的心 提交于 2019-11-27 02:59:51

Just to expand a bit, here's a .jshintrc setup for Mocha:

{
  ....
  "globals"   : {
    /* MOCHA */
    "describe"   : false,
    "it"         : false,
    "before"     : false,
    "beforeEach" : false,
    "after"      : false,
    "afterEach"  : false
  }
}

From the JSHint Docs - the false (the default) means the variable is read-only.

If you are defining globals only for a specific file, you can do this:

/*global describe, it, before, beforeEach, after, afterEach */
jshint: {
  options: {
    mocha: true,
  }
}

is what you want

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

/*global describe:true*/

Options

Add this in your .jshintrc

"predef" : ["define"]   // Custom globals for requirejs

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

"dojo": true

and thou shall rest peacefully without red warnings...

If you are working on node js. Add these two lines in the beginning of your file

/*jslint node: true */
"use strict";

Read the docs and search for /*global

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.

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