Rule Change: Add option to allow empty while loops to no-empty
See original GitHub issueWhat rule do you want to change?
no-empty
What change to do you want to make?
Implement suggestions
How do you think the change should be implemented?
A new option
Example code
const foo = () => {
console.log('Still going');
return Math.random() > 0.5;
};
while(foo()) {}
What does the rule currently do for this code?
It generates an error because empty while loops are banned.
What will the rule do after it’s changed?
Generate an error based on if the allow-empy-while-loops option is enabled.
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
This is useful when using Prettier because Prettier always formats empy while loops into empty blocks, which makes using Eslint and Prettier together really annoying because they can’t agree on what to do with empty while loops. Currently the only way to solve this is by turning of no-empty, which I think is unfortunate because it’s useful for catching other errors.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Loop while list not empty [duplicate] - python - Stack Overflow
The problem is the list l gets smaller after calling l.remove(value) , but subscript 'i' still try to index the original l ....
Read more >no-empty - ESLint - Pluggable JavaScript Linter
This rule has an object option for exceptions: "allowEmptyCatch": true allows empty catch clauses (that is, which do not contain a comment). allowEmptyCatch....
Read more >Ignore `catch` block in the `no-empty` rule · Issue #2808 - GitHub
I want the rule to catch empty blocks, but ignore the catch block as it's ... Add an option that defines exceptions in...
Read more >Is an empty 'while' loop bad practice?
Empty while loops An empty while loop is a bad idea. This isn't the best approach but it is an acceptable one...
Read more >while loop to repeat when condition is true - MATLAB while
An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am interested to work on this. can I pick this one? @Bwallker let me know if you are working on this.
VS Code supports suggestions.
Rules marked with 💡 in the list of rules provide suggestions.
For example, if you have this code:
\
will be underlined as an error. When you hover over it, VS Code will offer Quick Fix:First two options (
Remove the '\'...
, andReplace the '\' with '\\'...
) are suggestions provided by the no-useless-escape rule. When you click on a suggestion, it will fix the code.