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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14741110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:17:59  来源:igfitidea点击:

Have jshint ignore certain files when building Twitter Bootstrap

twitter-bootstrapbuildmakefilejslintjshint

提问by Lèse majesté

I often have this problem when using Twitter Bootstrap with other 3rd-party JS libraries, such as html5.jsfrom WordPress' "Twenty Twelve" theme, where the build fails because jshint(or jslintin previous versions of TB I think) throws an error due to the third-party JS library, e.g.

在将 Twitter Bootstrap 与其他 3rd-party 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

I'd like to avoid modifying third-party libraries or modify TB's Makefile, as that'll cause problems for upgrades in the future; is my only option to put 3rd-party JS files into a separate folder.

我想避免修改第三方库或修改TB的Makefile,因为这会导致以后升级出现问题;是我将 3rd-party JS 文件放入单独文件夹的唯一选择。

Is there a way to get jshint or TB's build process to ignore certain JS files (perhaps through some .jshintrcconfiguration I'm not aware of?)?

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

回答by Lèse majesté

So there is an option to ignore files in jshint, but it's not set within .jshintrcbut rather a separate file .jshintignore, which makes sense. However, while jshint will look for .jshintrcin your project's subdirectories, .jshintignoreneeds to be in the project root. So with Twitter Bootstrap, .jshintrcis in /jswhile .jshintignoreneeds to be placed in /.

所以有一个选项可以忽略 jshint 中的文件,但它不是设置在里面.jshintrc而是一个单独的文件.jshintignore,这是有道理的。但是,虽然 jshint 将.jshintrc在您项目的子目录中查找,但.jshintignore需要位于项目根目录中。所以使用 Twitter Bootstrap,.jshintrc/jswhile 中.jshintignore需要放置在/.

So to solve the problem in my question /.jshintignoreneeds to contain:

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

js/html5.js
js/theme-customizer.js

And that's it!

就是这样!

回答by Justin

As a supplement to Lèse majesté's answer, one can also write these comments in your JS and jshint will ignore the code in between:

作为 Lèse majesté回答的补充,您还可以在您的 JS 中编写这些注释,而 jshint 将忽略其间的代码:

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be linted with ignored by JSHint.
/* jshint ignore:end */

OR if you just want JSHint not to check a single line:

或者,如果您只想让 JSHint 不检查一行:

 // jshint ignore:line

Reference: jshint docs

参考:jshint 文档

回答by Ronnie

The simplest solution for me is I just add // jshint ignore: startto the top of whatever file I want ignored

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