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

Multiple variable declaration in the same line #98

Closed
ricardofbarros opened this issue Apr 1, 2015 · 17 comments

Comments

@ricardofbarros
Copy link
Contributor

commented Apr 1, 2015

Is this allowed?

  var a, b, c

  a = 2
  b = 3
  c = 4

  a + 1
  b + 1
  c + 1

Standard isn't complaining about multiple variable declaration in the same line and in your examples you have variable declaration in each line.

@Flet

This comment has been minimized.

Copy link
Member

commented Apr 1, 2015

Hmm, yeah not getting any warnings on this either.

flet@lappy:~/code$ cat blah.js 
var x, y, z
var q = 1, r = 2, s = 3
var a = 1, b, c
var m = 0
var n

a = 2
b = 3
c = 4

a + 1
b + 1

// semicolon to prove things are working!
c + 1;

x + y + z + q + r + s + a + b + c + m + n
flet@lappy:~/code$ standard blah.js 
Error: Use JavaScript Standard Style (https://github.com/feross/standard)
  blah.js:15:6: Extra semicolon.

flet@lappy:~/code$ standard --version
3.3.0
@Flet

This comment has been minimized.

Copy link
Member

commented Apr 1, 2015

ah, looks like the shiny new "one-var": [2, "never"], is not turned on!

@Flet

This comment has been minimized.

Copy link
Member

commented Apr 1, 2015

looks like turning this on breaks a lot of repos in test.js that are doing:

var i, j, l, tmp, placeHolders, arr
@Flet

This comment has been minimized.

Copy link
Member

commented Apr 1, 2015

@feross

This comment has been minimized.

Copy link
Member

commented Apr 1, 2015

D'oh! Multiple variable declarations in a single line should only be allowed when they're all undefined, like:

var a, b, c

I was so excited to release 3.3.0 to eliminate jscs and add the programmatic API that I forgot to enable "one-var": [2, "never"]. Let's wait until eslint/eslint#2206 is resolved before enabling this rule.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 3, 2015

I put up $20 on issue eslint/eslint#2206 in hopes it will get resolved soon. If anyone else wants to chip in, please do 👍

@ricardofbarros

This comment has been minimized.

Copy link
Contributor Author

commented Apr 3, 2015

Nice 😄, should we close this issue since it's a issue related with eslint?

@feross

This comment has been minimized.

Copy link
Member

commented Apr 4, 2015

No, let's leave it open so we don't forget.

@beaugunderson

This comment has been minimized.

Copy link

commented May 2, 2015

implemented in eslint/eslint@916277b but not in a release yet, will be in >0.20.0

@feross

This comment has been minimized.

Copy link
Member

commented May 3, 2015

Nice!

@feross

This comment has been minimized.

Copy link
Member

commented May 3, 2015

We're still blocked on eslint/eslint#2336. That needs to be fixed before we can start using the latest eslint.

@Flet

This comment has been minimized.

Copy link
Member

commented May 4, 2015

Not confident it 2336 will be fixed soon... could turn down the padded blocks rule temporarily I suppose...

@Flet

This comment has been minimized.

Copy link
Member

commented May 11, 2015

@feross any thoughts on relaxing the padded blocks rule in order to get to the latest eslint version?

@feross

This comment has been minimized.

Copy link
Member

commented May 11, 2015

@Flet Yeah, let's just do that. The padded block rule isn't important for correctness or catching errors.

@feross

This comment has been minimized.

Copy link
Member

commented May 11, 2015

I just tried adding the rule "one-var": [2, { initialized: "never" }]. Mostly works correctly, except it complains about:

var arr = [1, 2, 3]
for (var i = 0, len = arr.length; i < len; i++) {
  // ...
}

With this error: Split initialized 'var' declarations into multiple statements.

I'm inclined to hold off on this rule until we can ignore for loops somehow.

@feross

This comment has been minimized.

Copy link
Member

commented May 11, 2015

Issue opened here: eslint/eslint#2505

@feross

This comment has been minimized.

Copy link
Member

commented Jun 11, 2015

ESLint finally fixed the bug where multiple vars were being checked in for statements!

Released 4.2.0 with the new rule: "Split initialized 'var' declarations into multiple statements". Arguably this could have been a semver major change, but not a single clone test failed (and we have nearly 80 repos in there!), so the risk is low.

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 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.