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.

Comment in SwitchCase triggers newline-before-return

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Apr 2, 2016

Alright, sorry it took me a bit to get to this. I’ve verified this happens, but only with babel-eslint. The bug is that babel-eslint is incorrectly adding // no default as a leadingComment of the return statement. We had the same issue with espree (our default parser), but that has been fixed and is working as intended.

0reactions
scottoharacommented, Apr 4, 2016
Read more comments on GitHub >

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

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