New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(12077) line breaking with unary operators in conditional #12087
base: main
Are you sure you want to change the base?
fix(12077) line breaking with unary operators in conditional #12087
Conversation
I forgot to format the markdown, so I ran it. |
There are lots of other |
Co-authored-by: fisker Cheung <lionkay@gmail.com>
Co-authored-by: fisker Cheung <lionkay@gmail.com>
@fisker // printWidth: 25
// input
const c = {
prop1: foo == null ? bar : baz,
prop2: !fooooooooo ? bar : baz,
// Should Identifier also have a new line?
prop3: foooooooooo ? bar : baz,
};
// output
const c = {
prop1:
foo == null
? bar
: baz,
prop2:
!fooooooooo
? bar
: baz,
// Should Identifier also have a new line?
prop3:
foooooooooo
? bar
: baz,
}; |
Maybe we can try the opposite, instead of break before Prettier pr-12087 --parser babel
--print-width 25 Input: const x = {
prop1: !fooooooooo ? bar : baz,
prop1: fooooooooo ? bar : baz,
prop1: foooo.oooo ? bar : baz,
prop1: foooo.oo() ? bar : baz,
};
Output: const x = {
prop1:
!fooooooooo
? bar
: baz,
prop1: fooooooooo
? bar
: baz,
prop1: foooo.oooo
? bar
: baz,
prop1: foooo.oo()
? bar
: baz,
}; |
@fisker // printWidth: 18
// input
const x = {
prop1: foo === null ? bar : baz,
prop1: !fooooooooo ? bar : baz,
}
// output
const x = {
prop1: foo ===
null
? bar
: baz,
prop1:
!fooooooooo
? bar
: baz
} Therefore, we changed the pattern so that all patterns have a new line. |
I'm not familiar with this part, I don't know, sorry. |
The output looks good, I'll check later. |
I ran this change over some codebase, some case doesn't look good. mostly the variable declaration - const unwrappedInit = hasUnaryPrefix(init, '-')
- ? init.argument
- : init;
+ const unwrappedInit =
+ hasUnaryPrefix(init, '-') ? init.argument : init; Full diff prettier/prettier-regression-testing#130 |
If such a case exists, I guess I'll have to delete the new line before binaryExpression. |
…islandryu/prettier into fixLineBreakWithUnaryExpression
…ineBreakWithUnaryExpression
Remove newline before binaryExpression. Existing tests have been affected. |
It's fine to change the output. |
run_spec(__dirname, ["babel", "flow", "typescript"], { printWidth: 18 }); | ||
run_spec(__dirname, ["babel", "flow", "typescript"], { printWidth: 25 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the new tests longer to cross 80 width, so we can remove the printWidth
? Or you can put new tests into a new directory, the snap became very big, hard to review.
I'm running this over other codebases, let's see how this effect them prettier/prettier-regression-testing#130 (comment) |
I put the tests for |
Description
fix #12077
Unary operators within Conditional operators will break lines.
In other words, it does the same thing as the binary operator.
playground
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨