prettier / prettier/prettier

Chained object properties do not break after surpassing printWidth

Open
#16,441 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prettier 3.3.2
Playground link

--parser typescript
--print-width 20

Input:

function collapseBlankLines(n_lines: number = 3) {
        const blankThreshold = SuperExpressive()
            .atLeast(n_lines)
            .group 
            .zeroOrMore.whitespaceChar.newline.zeroOrMore.whitespaceChar
            .end()
            .allowMultipleMatches.toRegex()

        this._text = this.text.replaceAll(
            blankThreshold,
            '\n'
        )
        return this
    }

Output:

function collapseBlankLines(
  n_lines: number = 3,
) {
  const blankThreshold =
    SuperExpressive()
      .atLeast(
        n_lines,
      )
      .group.zeroOrMore.whitespaceChar.newline.zeroOrMore.whitespaceChar.end()
      .allowMultipleMatches.toRegex();

  this._text =
    this.text.replaceAll(
      blankThreshold,
      "\n",
    );
  return this;
}

Expected output:

function collapseBlankLines(
  n_lines: number = 3,
) {
  const blankThreshold =
    SuperExpressive()
      .atLeast(
        n_lines,
      )
      .group
      .zeroOrMore
      .whitespaceChar
      .newline
      .zeroOrMore
      .whitespaceChar
      .end()
      .allowMultipleMatches
      .toRegex();

  this._text =
    this.text.replaceAll(
      blankThreshold,
      "\n",
    );
  return this;
}

Why?
Check the PrintWidth!
Code should break when surpassing printWidth.
Example it's quite self-explanatory, if chaining methods, it will break, but no for object properties.

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

Reproduce the issue in the linked Prettier Playground using the TypeScript parser and print width 20. Compare the shown output with the expected output, then trace formatting for chained object properties; done means those properties break at the configured width without changing the other shown formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.