Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Object pattern formatting #2424

Closed
Tracked by #2403
MichaReiser opened this issue Apr 13, 2022 · 3 comments
Closed
Tracked by #2403

Object pattern formatting #2424

MichaReiser opened this issue Apr 13, 2022 · 3 comments
Assignees
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 13, 2022

Rome tries to fit all object pattern members on a single line. Prettier uses a more sophisticated approach to determine if the pattern should be formatted on a single line or broken across multiple ones. Playground

A few examples:

Input

// Break over multiple lines if it contains a sub pattern
const {b: {test}} = test;

// non-shorthand and whole statement exceeds line width
const { id, isStatic: isStatic, method, methodId, g } = privateNamesMap.get(name);

// default and whole statement exceeds line width
const { id, isStatic = true, method, methodId, gee } = privateNamesMap.get(name);

// sub pattern
const { id, isStatic: {sub}, method, methodId, gee } = privateNamesMap;

Prettier

// Break over multiple lines if it contains a sub pattern
const {
  b: { test },
} = test;

// non-shorthand and whole statement exceeds line width
const {
  id,
  isStatic: isStatic,
  method,
  methodId,
  g,
} = privateNamesMap.get(name);

// default and whole statement exceeds line width
const {
  id,
  isStatic = true,
  method,
  methodId,
  gee,
} = privateNamesMap.get(name);

// sub pattern
const {
  id,
  isStatic: { sub },
  method,
  methodId,
  gee,
} = privateNamesMap;

Rome

// Break over multiple lines if it contains a sub pattern
const { b: { test } } = test;

// non-shorthand and whole statement exceeds line width
const { id, isStatic: isStatic, method, methodId, g } = privateNamesMap.get(
  name,
);

// default and whole statement exceeds line width
const { id, isStatic = true, method, methodId, gee } = privateNamesMap.get(name);

// sub pattern
const { id, isStatic: { sub }, method, methodId, gee } = privateNamesMap;

Expected

Rome's formatting to match Prettier's

@MichaReiser MichaReiser changed the title Object destructuring formatting Object pattern formatting Apr 13, 2022
@MichaReiser MichaReiser added the A-Formatter Area: formatter label Apr 13, 2022
@ematipico ematipico self-assigned this Apr 14, 2022
@ematipico ematipico added the I-Normal Implementation: normal understanding of the tool and awareness label May 5, 2022
@ematipico
Copy link
Contributor

I will look after this one

@ematipico
Copy link
Contributor

Currently looking at implement this for type alias parameters

@ematipico
Copy link
Contributor

Currently looking at class members

Repository owner moved this from In Progress to Done in Rome 2022 Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants