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.
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 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 ...
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With