Comment in SwitchCase triggers newline-before-return
See original GitHub issueThis issue is similar to #5531 (raising as a separate issue on request of @kaicataldo).
// no default
comment in a SwitchCase
triggers newline-before-return
error.
What version of ESLint are you using? 2.5.3
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
/* eslint
newline-before-return: 'error'
default-case: 'error'
*/
What did you do? Please include the actual source code causing the issue.
function foo() {
switch ("foo") {
case "foo":
break;
// no default
}
return;
}
foo();
What did you expect to happen? No errors
What actually happened? Please include the actual, raw output from ESLint.
$ eslint foo.js
foo.js
9:2 error Expected newline before return statement newline-before-return
✖ 1 problem (1 error, 0 warnings)
Removing the comment fixes the error (but clashes with default-case
)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Inside a switch statement, newline-before-return conflicts with ...
A workaround is to move the comments to above the case labels, eg. function test(value) { switch (value) { // do something (this...
Read more >newline-before-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 >Switch statement for multiple cases in JavaScript
Use the fall-through feature of the switch statement. A matched case will run until a break (or the end of the switch statement)...
Read more >Pressing Enter in comment box unexpectedly submits form
I constantly mistakenly enter comments before I'm done with them due to enter doing the completely unexpected action of submitting (versus newline).
Read more >"switch case" clauses should not have too many lines of code
The switch statement should be used only to clearly define some new branches in the control flow. As soon as a case clause...
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 Free
Top 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
Alright, sorry it took me a bit to get to this. I’ve verified this happens, but only with
babel-eslint
. The bug is thatbabel-eslint
is incorrectly adding// no default
as aleadingComment
of thereturn
statement. We had the same issue withespree
(our default parser), but that has been fixed and is working as intended.Done. Thanks @mysticatea .
https://github.com/babel/babel-eslint/issues/289