78

我正在寻找一种方法,让 jscs(JavaScript 代码样式)执行与 jshint 相同的行为,以忽略每个文件的某些规则,顶部有注释,或者每行有一个开始和结束注释。

jshint 示例忽略文件中的特定规则:

/* jshint undef: false */

jshint 示例忽略块中的特定规则:

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

3 回答 3

119

这从 jscs 1.6.0 开始可用

对于文件范围:

将其放在文件顶部以忽略所有规则

// jscs:disable

将其放在文件顶部以忽略特定规则:

// jscs:disable specificRule

此外,为了忽略整个文件,您可以将其添加到.jscsrc,将条目添加到excludeFiles

对于块范围:

忽略所有规则

// Code here will be linted with JSCS.
// jscs:disable
// Code here will be ignored by JSCS.
// jscs:enable

要忽略特定规则:

// Code here will be linted with JSCS.
// jscs:disable specificRule
// Code here will be ignored by JSCS.
// jscs:enable specificRule
于 2014-08-09T21:16:26.710 回答
15

仅对一行禁用特定规则

// jscs:ignore maximumLineLength
于 2015-12-17T04:09:11.717 回答
3

要忽略整个文件,只需在文件顶部添加以下行。

// jscs:disable
于 2014-12-22T19:27:58.680 回答