Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: Mark return out of function #3612

Open
erosman opened this issue Mar 10, 2022 · 2 comments
Open

JavaScript: Mark return out of function #3612

erosman opened this issue Mar 10, 2022 · 2 comments

Comments

@erosman
Copy link

erosman commented Mar 10, 2022

I came across a code that had return out of function. It would be good if JSHint could also mark it.

Uncaught SyntaxError: return not in function
@jugglinmike
Copy link
Member

Thanks for the report! JSHint has silently tolerated this syntax error for a very long time; I'm a little surprised no one has reported it before.

There's some historical rational behind the behavior. By default, the Node.js runtime "wraps" JavaScript programs in an immediately-invoked function expression. A side-effect of that transformation is that developers can write return statements to interrupt control flow of the "top level" of their Node.js modules.

Unfortunately, it seems likely that many consumers are depending on the ability to use return like this. In an ideal world, JSHint would have only tolerated the apparently-invalid syntax if the node option were set to true. I'm afraid the ship's sailed on that, though.

So while we should certainly correct this, the fix will have to wait until the next major release of JSHint. We have no ETA on that today.

@erosman
Copy link
Author

erosman commented Mar 11, 2022

For the time being, instead of changing the default behaviour, which would be a breaking change, what about adding an Enforcing options for return?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants