Parsing error: 'return' outside of function

See original GitHub issue

Cannot disable one line /* eslint-disable-next-line */ or even the whole file at the top with /* eslint-disable */; both have no effect when the code contains a return outside of the function:

if (condition) {
    /* eslint-disable-next-line */
    return; // ESLint always errors here, can't avoid it
}

And it always bombs out with error Parsing error: 'return' outside of function.

I’m trying to add ESLint into a large test suit (jasmine) that’s been running successfully for years, and it uses the conditional return-s as shown above to stop certain test execution under special conditions.

I’ve been struggling to figure out how to make ESLint disregard that one line without success.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
mysticateacommented, Jun 20, 2017

This is working as intended.

  • globalReturn option cannot be used together with ES modules. Because both setting need special scope which is the child of the global scope.
  • env: node includes globalReturn option, so you don’t need specifying the option manually.
  • eslint-disable hides error reports from rules, but does not hide parsing errors of parsers.
0reactions
not-an-aardvarkcommented, Jul 2, 2017

Closing because this is working as intended.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: return not in function - JavaScript - MDN Web Docs
The JavaScript exception "return (or yield) not in function" occurs when a return or yield statement is called outside of a function.
Read more >
Error: 'return' outside of function in react js - Stack Overflow
Issue is semicolon after the render keyword. And render method is outside the class component due to wrongly placed brackets render(); {}.
Read more >
SyntaxError: 'return' outside function - Codecademy
My indenting is fine, I think, even though the indenting doesn't show here. The error is: File “python”, line 7 SyntaxError: 'return' outside...
Read more >
SyntaxError: script.js: 'return' outside of function `r` (6:4)
That's a syntax error, the function is supposed to wrap the rest of codes in. However, there's a few problems here.
Read more >
Python SyntaxError: 'return' outside function Solution
The “SyntaxError: 'return' outside function” error is raised when you specify a return statement outside of a function. To solve this error, ...
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