Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 255
Dancrumb Avatar asked May 26 '16 16:05

Dancrumb


People also ask

Can ESLint Auto-Fix linting errors?

However, sometimes there’s a situation where a project can have a lot of linting errors (i.e. adding ESLint to an existing project) and it would be tedious for a dev to fix them manually. Don’t worry, ESLint has a command for auto-fixing: eslint --fix!

How to Lint and format code with ESLint in Visual Studio Code?

How To Lint and Format Code with ESLint in Visual Studio Code Step 1 — Creating JavaScript Starter Code. You need to start with a demo project. ... Open app.js in Visual Studio Code. Step 2 — Setting Up ESLint. It’s important to include the --save-dev flag because this saves the package as a ...

Does ESLint--fix-dry-run overwrite the file?

eslint --fix-dry-run acts like fix but will not actually overwrite the file. Instead, specify an output location and a formatting option such as eslint --fix-dry-run --format=json -o ./test.test.json.

What is the output of ESLint--fix?

The output from eslint --fix will be a list of errors and warnings. If desired, warnings can be silenced with the --quiet flag. Conversely, if desired, a maximum number of errors can be specified as ‘too many’ ( --max-warnings [number] ), and the linter will succeed but end with exit code 1 (more on that below).


1 Answers

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.

like image 113
Benjamin Gruenbaum Avatar answered Oct 18 '22 06:10

Benjamin Gruenbaum