How to tell JSHint to ignore all undefined variables in one file?

前端 未结 4 1859
名媛妹妹
名媛妹妹 2021-02-05 01:27

In Karma tests, there are a lot of global variables and functions, which JSHint complains about (it is integrated into my editor).

How can I tell JSHint to ignore all u

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 02:14

    The correct way to tell JSHint about globals is to use the globals directive. For example:

    /*globals globalFunction, anotherGlobal, oneMore */
    

    This will prevent "{a} is not defined" warnings when JSHint encounters any of the listed identifiers.

    Alternatively, if you really want to ignore all "not defined" warnings in that file, and you're using JSHint 1.0.0 or above, you can simply turn off that specific warning:

    /*jshint -W117 */
    

提交回复
热议问题