[英]Put semicolons in asi mode before brackets
I'm linting my JavaScript with JSHint, and have this option enabled我正在用 JSHint 整理我的 JavaScript,并启用了这个选项
"asi": true,
"white": true
to avoid semicolons in my code.避免在我的代码中使用分号。
But I have to begin my new line with a bracket, so I have to put a semicolon before the opening of that one但是我必须用括号开始我的新行,所以我必须在那个开始之前放一个分号
;(function () {
})
JSHint give me two errors: JSHint 给我两个错误:
I noticed that in this way JSHint is happy我注意到这样 JSHint 很开心
;
(function () {
})
but I think is not a good solution.但我认为这不是一个好的解决方案。
Is there a way to solve this problem, without turning off JSHint or the white option?有没有办法在不关闭 JSHint 或白色选项的情况下解决这个问题?
The legacy white: true
option in JSHint is used to enforce the coding style promoted by Douglas Crockford in his original JSLint tool. JSHint 中遗留的
white: true
选项用于强制执行Douglas Crockford在其原始JSLint工具中提倡的编码风格。 Semicolon-less JavaScript code will not fit his coding style.没有分号的 JavaScript 代码不适合他的编码风格。 If you don't want to be restricted to his style guidelines then don't use
white: true
.如果你不想受限于他的风格指南,那么不要使用
white: true
。
This list of JSHint options doesn't show any parameters to customize the coding style they enforce.这个 JSHint 选项列表没有显示任何参数来自定义它们强制执行的编码风格。
To prove that there isn't an answer to this, I went and found the relevant check in the JSHint source:为了证明这个问题没有答案,我去 JSHint 源代码中找到了相关检查:
function nonadjacent(left, right) {
if (option.white) {
left = left || token;
right = right || nexttoken;
if (left.line === right.line && left.character === right.from) {
left.from += (left.character - left.from);
warning("Missing space after '{a}'.",
left, left.value);
}
}
}
The only configuration option checked is option.white
, so unfortunately there isn't any way to achieve your desired behavior.唯一检查的配置选项是
option.white
,所以很遗憾,没有任何方法可以实现您想要的行为。 If you really wanted a tool that would do exactly what you want, you could easily fork JSHint , add another option, and check it in the nonadjacent
function.如果您真的想要一个能够完全满足您需求的工具,您可以轻松地 fork JSHint ,添加另一个选项,然后在非
nonadjacent
函数中检查它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.