【问题标题】:JSHint and JSCS inline ignore for the same next lineJSHint 和 JSCS 内联忽略同一下一行
【发布时间】:2015-09-24 14:37:31
【问题描述】:
是否有可能以某种方式使 JSHint 和 JSCS 在同一下一行的内联忽略中很好地发挥作用?
我想做这样的事情:
/* jshint camelcase: false, jscs requireCamelCaseOrUpperCaseIdentifiers: false */
我尝试了几种不同的变体(单独的“评论块”,中间的分号,不同的行用于忽略),但无法使其工作。也许我错过了一些明显的东西?还是根本不可能?谢谢。
【问题讨论】:
标签:
javascript
jshint
jscs
【解决方案1】:
JSHint 不允许为一行禁用特定规则,但可以禁用一行的所有验证:
var do_something; /* jshint ignore:line */
对于 JSCS,启用/禁用单个规则的语法如下:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
...
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
综合起来,要禁用特定行的 JSHint 和 JSCS 验证,可以使用上述 cmets 的组合:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var var_name_with_underscores; /* jshint ignore:line */
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
如果非驼峰式标识符在块内的多行中使用(通常是规则),则可能需要将整个函数包含在 cmets 中。
// jscs: disable requireCamelCaseOrUpperCaseIdentifiers
/* jshint ignore:start */
function foo()
{
var var_name_with_underscores;
...
var_name_with_underscores = 123;
...
}
/* jshint ignore:end */
// jscs: enable requireCamelCaseOrUpperCaseIdentifiers