guides icon indicating copy to clipboard operation
guides copied to clipboard

[JS Styleguide] - Disallows multiple `var` declaration

Open azevedo opened this issue 10 years ago • 5 comments

https://github.com/jscs-dev/node-jscs/blob/f55bbae8bfbd8d57a4f756193d824e6f398ff7a7/lib/rules/disallow-multiple-var-decl.js

Basically I'd go for the exceptUndefined mode.

I happen to do this a lot:

  var a, b;
  // use later on

azevedo avatar Apr 07 '15 14:04 azevedo

What's wrong with this?

var a = 1,
    b = 2;

The only issue I can think of is if you want to remove or move either the first or last declaration. Is this enough to disallow it, or is there something else?

zamith avatar Apr 08 '15 08:04 zamith

Can't think of any reasons besides those. Actually I think i did assume we were going with a strict approach and this was an attempt to use a more loose one. Nevertheless, I don't think allowing multiple declarations, like your example, brings any benefits.

azevedo avatar Apr 08 '15 13:04 azevedo

My only issue, if you can call it that, with this, is that it seems a bit incoherent to force this, and not go with comma first on object definition. It seems to me the same exact problems are present in both situations, wouldn't you say?

zamith avatar Apr 08 '15 13:04 zamith

Similar only in the moving around part. My problem with comma first is that it doesn't look good ;) So I would not put these in the same bag

azevedo avatar Apr 08 '15 14:04 azevedo

Hum... I don't think this way of declaring variables looks good as well, but I understand the possible benefits. I also don't like comma first, but both situations seem very similar to me, and it seems strange to suggest one and oppose the other.

zamith avatar Apr 08 '15 14:04 zamith