javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Question: do you enforce multiline new lines for destructuring?

Open kjenkins19 opened this issue 5 years ago • 4 comments

We are having a debate around whether the AirBnB guidelines for object-curly-newline (10.8) should affect destructuring or not, particularly for props.

Example:

// Good
export default function myComponent({ prop1, prop2, prop3 }) { ... }

export default function myComponent({ 
 prop1, prop2, prop3,
}) { ... }

export default function myComponent({ 
 prop1,
 prop2,
 prop3,
}) { ... }

// Is this bad?
export default function myComponent({ 
 prop1, prop2, 
 prop3, 
}) { ... }

// Good
const { env1, env2, env3 } = process.env;

// Is this bad?
const { 
  env1, env2,
  env3,
} = process.env;

We know eslint does not support this at all (and have chosen not to), so if we want to do it we have to use prettier or eslint-plugin-putout. We are curious if AirBnB standards have been defined for this circumstance? There has been many discussions around whether rules 7.15 and 10.8 were intended to affect this.

Many thanks for your time. I apologize if this was answered elsewhere, couldn't seem to find it.

kjenkins19 avatar Jun 02 '21 13:06 kjenkins19

Yes, those examples you’re asking about are bad (the 2nd, 4th, and 6th).

Any multi-part construct that can’t fit entirely on a single line, must have each part on its own line. For destructuring, that means either the entire statement is on one line, or each property being destructured must be on its own line.

ljharb avatar Jun 02 '21 14:06 ljharb

To be clear, the guide dictates this, and it’s irrelevant that the linter config does not, as not everything in the guide is, or needs to be, lintable.

ljharb avatar Jun 02 '21 15:06 ljharb

@ljharb Thank you very much for the clarification. Would you be willing to point to where in the guide this is dictated? This isn't the first time this has come up for our team, as I believe half of us are misinterpreting the guide around this concept. I would like to update our documentation appropriately to make sure we are all on the same page moving forward.

kjenkins19 avatar Jun 02 '21 15:06 kjenkins19

You’re right; i don’t see an explicit section in the guide about it - but it should follow from principles of consistency.

A PR to make the guide more explicit here would be appreciated.

ljharb avatar Jun 02 '21 15:06 ljharb