Chained object properties do not break after surpassing printWidth
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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