2

我有这个应用程序非常模块化,因此,JSHint 给了我'x' is defined but never used错误。

我的设置是这样的:

应用程序/资产/脚本/bootstrap.js: var x = 5;

应用程序/资产/脚本/kickstart.js: console.log(x);

这是我从 JSHint 得到的输出:

app/assets/scripts/bootstrap.js
  line 1  col 6   'x' is defined but never used.

app/assets/scripts/kickstart.js
  line 1  col 13  'x' is not defined.

2 problems

我知道我可以使用类似的东西,/* exported x */但如果我有很多这样的变量,那就太麻烦了。

无论如何,在不禁用其特定选项的情况下解决这两个问题吗?因为它们可以在其他更重要的情况下派上用场。

4

1 回答 1

3

您可以在文件顶部添加它。

/*jshint unused: false, undef:false */

请注意,选项可以应用于特定范围。这适用于unused,但显然不适用于undef

(function () {
  /*jshint unused: false */

  // Stuff
}());
于 2014-03-20T03:37:20.617 回答