为什么ESLint在使用光纤的同时(true)触发lint错误? [英] Why does ESLint trigger lint errors on while(true) using fibers?

查看:97
本文介绍了为什么ESLint在使用光纤的同时(true)触发lint错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我带来了一些无限循环的JS代码(我们使用节点光纤来发生事情)。

I have come JS code with some infinite loops (we're using node-fibers to allow things to happen).

ESLint讨厌:

while (true) {

}

因为条件不变。

以下是允许的:

for(;;) {

}

除了喂养lintbeast之外,还有任何客观理由支持 超过(反之亦然)?

Beyond just feeding the lintbeast, are there any objective reasons to favour for over while (or vice versa)?

注意:此问题明确要求客观原因,因此不仅仅是基于意见。

NOTE: This question is explicitly requesting objective reasons and so is not simply opinion based.

推荐答案

这些关于无限循环的规则来自于生成器之前的东西,甚至不知道纤维。

These rules about infinite loops are from before generators were a thing and are not even aware of fibers.

假设每个函数永远不会挂起并返回(如生成器, async -keyword函数或光纤),该规则会产生很多ense警告循环中的常量。

Under the assumption that every function never suspends and returns (like a generator, async-keyword function or a fiber) the rule makes a lot of sense to warn against constants in loops.

现在时间已经改变 - 规则不再有意义,你正在做的事情完全没问题。

Now that times have changed - the rule no longer makes sense and what you're doing is perfectly fine.

如果我们检查 eslint repo ,我们会讨论并且在此期间被认为不够重要:

If we check the eslint repo it was discussed and deemed "not important enough to acknowledge" in the meantime:


我认为这不是一个内置异常。如果您这样做,那么最好使用注释手动禁用生成器中的规则。

I don't think this makes sense as a built-in exception. If you're doing that, then it's best to manually disable the rule in the generator using a comment.

解决方法<$ c建议使用$ c> for(;;)但是每个参与者都知道这是针对这种特殊情况的黑客攻击。

The workaround for(;;) was suggested but everyone involved understands it's a hack for this particular case.

禁用规则。

这篇关于为什么ESLint在使用光纤的同时(true)触发lint错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆