issue with a nested unary (not) condition
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 52.3k
- Forks
- 5k
- Avg merge
- 19h 2m
- Merged PRs (30d)
- 117
Description
Prettier 2.0.5
Playground link
--parser babel
Input:
if (veryFirstCondition ||
(guardCondition1 &&
guardCondition2 &&
guardCondition3 &&
!(negativeTestCondition1 &&
looooooooooongNegativeTestCondition &&
negativeCondition3)) // <===
) {
doSOmething()
}
Output:
if (
veryFirstCondition ||
(guardCondition1 &&
guardCondition2 &&
guardCondition3 &&
!(
negativeTestCondition1 &&
looooooooooongNegativeTestCondition &&
negativeCondition3
)) // <===
) {
doSOmething();
}
Expected behavior:
if (
veryFirstCondition ||
(guardCondition1 &&
guardCondition2 &&
guardCondition3 &&
!(
negativeTestCondition1 &&
looooooooooongNegativeTestCondition &&
negativeCondition3
)
) // <===
) {
doSOmething();
}
Something similar but without the veryFirstCondition part seems to be formatted correctly:
Prettier 2.0.5
Playground link
--parser babel
Input:
if (
guardCondition1 &&
guardCondition2 &&
guardCondition3 &&
!(negativeTestCondition1 &&
looooooooooongNegativeTestCondition &&
negativeCondition3)) {
doSOmething()
}
Output:
if (
guardCondition1 &&
guardCondition2 &&
guardCondition3 &&
!(
negativeTestCondition1 &&
looooooooooongNegativeTestCondition &&
negativeCondition3
)
) {
doSOmething();
}
I did try the same thing with the recent updates from the master branch, with the same result.
I think this is not a super major issue but it would be nice to see it fixed someday.
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 formatting difference from the linked Playground with the babel parser and the nested unary-condition input. Compare the actual output with the expected closing-parenthesis and comment placement, then locate the formatter tests covering similar conditional expressions and add a regression case whose output matches the expected example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100