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

Semicolon before IIFE should be mandatory #1123

Closed
MatthewCochrane opened this issue May 3, 2018 · 5 comments

Comments

@MatthewCochrane
Copy link

commented May 3, 2018

The following code produces a rather cryptic javascript error when run

console.log("hello world")
(function () {
  // Extra logic goes here. (see below)
})()

Here's the console output you get when you run it: (try running it in your browser now (ctrl-shift-j))

VM46685:1 hello world
VM46685:2 Uncaught TypeError: console.log(...) is not a function
    at <anonymous>:2:1
(anonymous) @ VM46685:2

Eslint does not give any warnings or errors. The standard mode forces us to omit semicolons, so I propose that a rule to help avoid this case should be added to the standard. Those with more experience than me can probably better suggest an implementation.

A starting point could be:

any line starting with a ( character should require a ; before it
@CiQL

This comment has been minimized.

Copy link

commented May 9, 2018

There already exists a rule for this:

Never start a line with (, [, or `. This is the only gotcha with omitting semicolons, and standard protects you from this potential issue.
eslint: no-unexpected-multiline

I don't know why it doesn't give you any warnings or errors, though.

@lukehutton

This comment has been minimized.

Copy link

commented May 24, 2018

I don't get any errors when have code like this in separate js file, shouldn't there be error for no-unexpected-multiline ?

// ✗ avoid
(function () {
  window.alert('ok')
}())
@feross

This comment has been minimized.

Copy link
Member

commented May 25, 2018

@mattisback What version of standard are you using?

Using standard@11.0.1 I get an error with your example:

/Users/feross/code/standard/t.js:2:1: Unexpected newline between function and ( of function call.

I think you're likely using an old version of standard.

@feross

This comment has been minimized.

Copy link
Member

commented May 25, 2018

@lukehutton You're referring to a separate issue. See #786

@no-response no-response bot closed this Jun 1, 2018

@no-response

This comment has been minimized.

Copy link

commented Jun 1, 2018

This issue has been automatically closed because there was no response to a request for more information from the issue opener. Please leave a comment or open a new issue if you have additional information related to this issue.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 30, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.