bufferapp / javascript-style-guide

Buffer's JavaScript style guide
23 stars 5 forks source link

Multi-line variable declaration style #4

Closed djfarrelly closed 9 years ago

djfarrelly commented 9 years ago

I'm proposing a to add common variable declaration style to this guide. The most popular styles are:

// one-var per declaration
var isOpen = true;
var name = 'Bill';

// multi use of var
var isOpen = true,
    name = 'Bill';

// comma-first
var isOpen = true
  , name = 'Bill'
  ;

After personally changing my style over the years between all 3 above, I'm a big fan of the one-var per declaration and I think most of the code in the buffer-web repo is this way too. Airbnb has a couple good points in their style guide.

I think a case for comma first is that in a commit, when removing a variable, you're only editing that single line and not having to adjust a comma or semi colon on the line above or below. You also has this benefit with the one-var per line.

Similar to this issue in the PHP style guide, I personally think it's great to keep consistent with the codebase over creating a new style: https://github.com/bufferapp/buffer-php-style-guide/issues/3

What do you guys think?

cc @nieldlr @msanroman

msanroman commented 9 years ago

That's a good one, @djfarrelly! I think I settled up with comma-first most of the time since the linter used on my previous job forced us to do multi use of var, but didn't give it much thought.

Happy to keep it consistent, and I like the one-var per declaration approach! :+1:

Also, I like the idea of keeping unassigned vars at the end of the declaration block :smile:

nieldlr commented 9 years ago

Woop! Thanks for starting this one @djfarrelly. I've always seemed to gravitate to the one-var per line style. So I'm totally keen on that one too. :+1: