Why does ESLint trigger lint errors on while(true) using fibers?

一个人想着一个人 提交于 2019-12-23 07:37:26

问题


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

ESLint hates:

while (true) {

}

because of the constant condition.

The following is allowed though:

for(;;) {

}

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.


回答1:


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

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.

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.

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

Disable the rule.



来源:https://stackoverflow.com/questions/37466508/why-does-eslint-trigger-lint-errors-on-whiletrue-using-fibers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!