question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule Change: Add option to allow empty while loops to no-empty

See original GitHub issue

What 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:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
amareshsmcommented, May 13, 2022

I am interested to work on this. can I pick this one? @Bwallker let me know if you are working on this.

1reaction
mdjermanoviccommented, May 20, 2022

Got it. Where we can see these suggestions? It is mentioned suggestions will be shown in the editor but I am not able to reproduce them. Can someone help me with this? I would like to see how suggestions will be shown to the users.

VS Code supports suggestions.

Rules marked with 💡 in the list of rules provide suggestions.

For example, if you have this code:

/* eslint no-useless-escape: "error" */

"\a"

\ will be underlined as an error. When you hover over it, VS Code will offer Quick Fix:

image

image

First two options (Remove the '\'..., and Replace the '\' with '\\'...) are suggestions provided by the no-useless-escape rule. When you click on a suggestion, it will fix the code.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found