Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve prefer-while: ignore 'for' without condition #196

Closed
foxfriends opened this issue Feb 11, 2021 · 3 comments · Fixed by #248
Closed

Improve prefer-while: ignore 'for' without condition #196

foxfriends opened this issue Feb 11, 2021 · 3 comments · Fixed by #248
Assignees
Milestone

Comments

@foxfriends
Copy link

I want to request a feature.

When I write an infinite loop, I want to write for (;;) {}, but prefer-while gets flagged, forcing me to instead write while (true) but then another linter says "no constant conditions" and I'm back to the for loop.

Could an option for prefer-while be added that allows the infinite for loop to be used?

@Loxos
Copy link
Contributor

Loxos commented Feb 12, 2021

Changing the behaviour of prefer-while to actually prefer a specific for loop which only has a condition seems counter-intuitive to me.

Especially as no-constant-condition already has an option to ignore constant conditions in loops.

The following settings should allow you to use while(true){...} and do{...}while(true):

no-constant-condition: ["error", { "checkLoops": false }]

@foxfriends
Copy link
Author

I would think it's more like allowing empty for, rather than preferring empty for. Same feel as any exception to other eslint rules. The empty for loop is also not so much "a specific for loop which only has a condition" but rather a for loop without a condition? Since a while loop cannot be without a condition, this is a special ability of the for loop that I would like to allow.

While ignoring constant conditions in loops is an option that allows writing an infinite loop, there is still no way to write the infinite for loop without disabling something.

@vilchik-elena
Copy link
Contributor

I agree rule should not trigger if for does not have a condition, the purpose of the rule is to use while(condition) when only condition is defined for for.

@vilchik-elena vilchik-elena modified the milestone: 0.9.0 Jun 30, 2021
@vilchik-elena vilchik-elena changed the title Do not prefer-while over infinite for loop Improve prefer-while: ignore 'for' without condition Jul 1, 2021
@vilchik-elena vilchik-elena self-assigned this Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants