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

前端 未结 4 1857
名媛妹妹
名媛妹妹 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:10

    I've found myself using jshint ignore:line as a way of addressing this need:

    var unusedVar; // jshint ignore:line

    This allows jshint to continue its useful checking for this condition but where there are explicit reasons to ignore a specific declaration than adding this both addresses the issue and does it in a way that is immediately apparent to anyone looking at the code.

    A good example (at least for me), is when using ES6's destructuring to illicit a set of shortcuts that you may or may not use all the time. In Ember, I often use many of the methods that hang off of it such as typeOf and computed. Rather than always referring to Ember.computed it's far nicer to just refer to computed and have something like the following at the top of all my Ember objects:

     const { computed, $, A, run, on, typeOf, debug, get, set } = Ember;    // jshint ignore:line
    

提交回复
热议问题