prettier / prettier/prettier

RFC: don't preserve line breaks in object literals if all the properties are shorthand

Open
#8,055 13 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:object literals lang:javascript
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Let's format

const name = {
  firstName,
  lastName,
};

into

const name = { firstName, lastName };

Thoughts? Counterexamples?


Update, based on the discussion below:

Line breaks should not be preserved if

  • all the properties are shorthand or
  • the first property is a spread whose operand is an identifier and the rest of the properties are shorthand.

If the object literal contains empty lines or comments, line breaks should be preserved (the current behavior is kept).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the object-literal examples in the issue with the formatter and reviewing the current behavior for shorthand properties, identifier spreads, comments, and empty lines. Done means the stated line-break rules are implemented without changing preservation around comments or empty lines, with formatting behavior verified against the examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.