no-useless-return and no-empty conflict
See original GitHub issueTell us about your environment
- ESLint Version: 5.6.1
- Node Version: 10.11.0
- npm Version: 6.4.1
What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration: My configuration is insanely elaborate covering most of the rules in depth, for an easy to verify example use this
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. See the demo for a live example of source code that causes this issue, try clearing line 3.
eslint . --ext .js
What did you expect to happen?
One of the two wouldn’t error, in order to avoid conflict which each other. Even --fix
conflicts with these rules.
What actually happened? Please include the actual, raw output from ESLint.
without --fix
../src/utility/LibraryHandler.js
65:11 error Unnecessary return statement no-useless-return
with --fix
../src/utility/LibraryHandler.js
64:46 error Empty block statement no-empty
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
no-useless-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >@studiometa/eslint-config - npm package | Snyk
no-empty-function, 'error' ... no-useless-return, 'warn' ... plugin turns off all ESLint stylistic rules that might conflict with Prettier.
Read more >eslint/CHANGELOG.md - UNPKG
1007, * 4d35a81 Fix: Add a utility to avoid autofix conflicts (fixes #7928, ... 1125, * ca1f841 Fix: no-useless-return stack overflow on loops...
Read more >Code Issues - Embold Help Center
AvoidEnumAsIdentifier, Use of the term 'enum' will conflict with newer versions of Java ... no-empty, Empty blocks are often indicators of missing code....
Read more >hterm and Secure Shell - 1.92.1, 2022-03-04, Minor bug fixes.
... eslint: Enable no-empty check. eslint: Enable prefer-rest-params check. ... eslint: Enable no-useless-return checks. eslint: Enable no-useless-escape ...
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
To clarify, if code after the
if
/else
statement isn’t supposed to be executed, then usingreturn
is fine (andno-useless-return
won’t report an error if there are additional statements).Even if there aren’t additional statements after the
if
/else
, if the first case is conceptually supposed to be an “early exit” it might be clearer to write it this way:If the first case isn’t conceptually an “early exit” and
return
is being used as a placeholder for “do nothing”, then it seems clearer to actually do nothing (perhaps with a comment clarifying this choice), otherwise the use ofreturn
could be misleading to people reading/modifying the code in the future.@LJNeon The reasoning for adding a comment is that it can help explain to readers of your code why the block is empty, when it might otherwise appear that it was a mistake. For example, you could write something like this:
In other words, adding a comment to the block is less of a workaround to appease the linter, and more of a mechanism for making sure your code is readable. Using
return;
in this case isn’t ideal because it could cause unexpected results if you need to add additional statements after theif
/else
statement (namely, those statements will be skipped).