我创建了以下 isqrt 函数。
function isqrt(n) {
var shift, result, candidateResult;
if (n < 0) {
return false;
}
for (shift = 2; n >> shift; shift += 2) {}
for (result = 0, shift -= 2; shift >= 0; shift -= 2) {
result = result << 1;
candidateResult = result + 1;
if (candidateResult * candidateResult <= n >> shift) {
result = candidateResult;
}
}
return result;
}
这里有一个空 block 。
for (shift = 2; n >> shift; shift += 2) {}
但这是故意的。 我知道我可以按如下方式改进此代码。
shift = 2;
while (n >> shift) {
shift += 2;
}
但我不想要它。
我在 Windows 10 上使用最新版本的支架。:)
最佳答案
您可以忽略整个文件或特定行或给定 block 的 jshint 规则。
忽略行:
function isqrt(n) {
var shift, result, candidateResult;
if (n < 0) {
return false;
}
for (shift = 2; n >> shift; shift += 2) {} // jshint ignore:line
for (result = 0, shift -= 2; shift >= 0; shift -= 2) {
result = result << 1;
candidateResult = result + 1;
if (candidateResult * candidateResult <= n >> shift) {
result = candidateResult;
}
}
return result;
}
忽略 block
/* jshint ignore:start */
// Code here will be ignored by JSHint. So write your code here
/* jshint ignore:end */
// Code here will be linted with JSHint.\
或者只写 //jshint ignore: start
在文件的开头然后整个文件将被忽略
关于javascript - 我可以在 Brackets 中禁用 jslint 的 'empty block' 警告吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48517250/