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

Question: do you enforce multiline new lines for destructuring? #2435

Open
kjenkins19 opened this issue Jun 2, 2021 · 4 comments
Open

Question: do you enforce multiline new lines for destructuring? #2435

kjenkins19 opened this issue Jun 2, 2021 · 4 comments

Comments

@kjenkins19
Copy link

kjenkins19 commented Jun 2, 2021

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.

@ljharb
Copy link
Collaborator

ljharb commented Jun 2, 2021

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
Copy link
Collaborator

ljharb commented Jun 2, 2021

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.

@kjenkins19
Copy link
Author

kjenkins19 commented Jun 2, 2021

@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.

@ljharb
Copy link
Collaborator

ljharb commented Jun 2, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ljharb @kjenkins19 and others