Fix the union type that contains an extra empty line (#18197)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
3 files changed
+32
-6
No files matched your search
@@ -0,0 +1,21 @@
|
||||
#### Remove extra empty line in union type (#18197 by @Dunqing)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla =
|
||||
Fooo1000 | Baz2000 | BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong;
|
||||
|
||||
// Prettier stable
|
||||
type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla =
|
||||
|
||||
| Fooo1000
|
||||
| Baz2000
|
||||
| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong;
|
||||
|
||||
// Prettier main
|
||||
type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla =
|
||||
| Fooo1000
|
||||
| Baz2000
|
||||
| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong;
|
||||
```
|
||||
@@ -62,6 +62,7 @@ function fits(
|
||||
}
|
||||
|
||||
let restCommandsIndex = restCommands.length;
|
||||
let hasPendingSpace = false;
|
||||
/** @type {Array<Omit<Command, 'indent'>>} */
|
||||
const commands = [next];
|
||||
// `output` is only used for width counting because `trim` requires to look
|
||||
@@ -82,6 +83,12 @@ function fits(
|
||||
switch (docType) {
|
||||
case DOC_TYPE_STRING:
|
||||
if (doc) {
|
||||
if (hasPendingSpace) {
|
||||
output += " ";
|
||||
remainingWidth -= 1;
|
||||
hasPendingSpace = false;
|
||||
}
|
||||
|
||||
output += doc;
|
||||
remainingWidth -= getStringWidth(doc);
|
||||
}
|
||||
@@ -142,8 +149,7 @@ function fits(
|
||||
return true;
|
||||
}
|
||||
if (!doc.soft) {
|
||||
output += " ";
|
||||
remainingWidth--;
|
||||
hasPendingSpace = true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+3
-4
@@ -142,10 +142,9 @@ type A3 = // dir, exp, arg, modifiers
|
||||
[string, ExpressionNode, ExpressionNode, ObjectExpression];
|
||||
|
||||
type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla =
|
||||
|
||||
| Fooo1000
|
||||
| Baz2000
|
||||
| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong;
|
||||
| Fooo1000
|
||||
| Baz2000
|
||||
| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong;
|
||||
|
||||
type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBl2 =
|
||||
Fooo1000 &
|
||||
|
||||
Reference in new issue
Block a user