ASHdevelopment / standards

ASH Development Standards
28 stars 13 forks source link

Trailing or "Final" commas #192

Open ASH-Michael opened 5 years ago

ASH-Michael commented 5 years ago

Should we add a standard for using trailing commas in our JavaScript?

In Arrays?

var arr = [ 1, 2, 3, ];

In Objects?

var object = { 
  company: "ASH", 
  team: "Front End",
};

In Functions? Only works in ecmaVersion 2017

function f(p) {}
function f(p,) {} 

(p) => {};
(p,) => {};

In Array and Object Destructuring?

let [a, b,] = [1, 2];

let o = {
  p: 42, 
  q: true,
};
let {p, q,} = o;
ASH-Michael commented 5 years ago

I am assuming we want trailing commas in both objects and arrays.

ASH-Michael commented 5 years ago

Some of our applications are on ecmaVersion 2015 and so will not support trailing commas in function argument lists.

Should we have a standard for that for all apps that use es2017? Do we want trailing commas to be used in function argument lists?

ASH-Michael commented 5 years ago

Should we require trailing commas when destructuring?

ASH-Bryan commented 5 years ago

I don't think there should be a standard either way, personally.

ASH-Michael commented 5 years ago

I don't think there should be a standard either way, personally.

@ASH-Bryan Can you share your thoughts on this? I didn't think there was any opposition to standardizing trailing commas.

ASH-Bryan commented 5 years ago

I think we should be careful how many standards we add - the more we create, the harder it will be for the team to internalize and follow them all. In my opinion we should be creating standards for things that have a real impact in some way; this feels more like a style decision to me. I'm open to being convinced otherwise!