在构建Twitter Bootstrap时让jshint忽略某些文件

Lès*_*sté 39 makefile build jslint jshint twitter-bootstrap

当我将Twitter Bootstrap与其他第三方JS库一起使用时,我常常遇到这个问题,例如html5.js来自WordPress的"Twenty Twelve"主题,其中构建失败,因为jshint(或者jslint我以前认为TB的先前版本)由于第三个而引发错误-party JS库,例如

\n##################################################
Building Bootstrap...
##################################################\n
js/html5.js: line 3, col 122, Expected ')' to match '(' from line 3 and instead
  saw ','.
js/html5.js: line 3, col 140, Expected an identifier and instead saw ')'.
js/html5.js: line 4, col 101, eval is evil.
js/html5.js: line 6, col 369, Confusing use of '!'.
js/html5.js: line 6, col 422, Confusing use of '!'.
js/html5.js: line 7, col 61, 'b' is already defined.
js/theme-customizer.js: line 26, col 26, Use '===' to compare with ''.

7 errors
make: *** [build] Error 1
Run Code Online (Sandbox Code Playgroud)

我想避免修改第三方库或修改TB的Makefile,因为这会在将来导致升级问题; 是我将第三方JS文件放入单独文件夹的唯一选择.

有没有办法让jshint或TB的构建过程忽略某些JS文件(可能通过.jshintrc我不知道的某些配置?)?

Lès*_*sté 96

因此,有一个选项可以忽略jshint中的文件,但它没有设置在内.jshintrc,而是一个单独的文件.jshintignore,这是有道理的.但是,虽然jshint将.jshintrc在项目的子目录中查找,但.jshintignore需要在项目根目录中.因此,与Twitter的引导,.jshintrc/js同时.jshintignore需要放置在/.

所以要在我的问题中解决问题/.jshintignore需要包含:

js/html5.js
js/theme-customizer.js
Run Code Online (Sandbox Code Playgroud)

就是这样!

  • 显然,一些通配符类型的魔法也可以工作,例如`js/vendor/*` - 如果你想要忽略供应商文件夹下的所有内容. (5认同)
  • 感谢发布这个 - 我很惊讶[`.jshintignore`目前没有记录](https://github.com/jshint/jshint/issues/1745). (2认同)

Jus*_*tin 34

作为Lèsemajesté 答案的补充,您也可以在JS中编写这些注释,jshint将忽略其间的代码:

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be linted with ignored by JSHint.
/* jshint ignore:end */
Run Code Online (Sandbox Code Playgroud)

或者,如果您只是希望JSHint不检查单行:

 // jshint ignore:line
Run Code Online (Sandbox Code Playgroud)

参考:jshint docs


Ron*_*nie 14

对我来说最简单的解决方案是我只是添加// jshint ignore: start到我想要忽略的文件的顶部