* 7920 run tests for trailingComma:es5 option as well * 7920 example of wrong behavior - comma is always added at the end of the inexact object type * 7920 add test cases for trailingComma: 'all' * 7920 fix - do not force trailing comma on explicit inexact type if it has indexer or no properties * 7920 add changelog
This commit is contained in:
1 parent
7047fadaa3
commit
964230dce2
6 files changed
+589
-6
No files matched your search
@@ -0,0 +1,52 @@
|
||||
#### Do not add comma for explicit inexact object with indexer property or no properties ([#7923](https://github.com/prettier/prettier/pull/7923) by [@DmitryGonchar](https://github.com/DmitryGonchar))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
type T = {
|
||||
a: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type T = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type T = {
|
||||
// comment
|
||||
...,
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
type T = {
|
||||
a: number,
|
||||
...
|
||||
}
|
||||
|
||||
type T = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type T = {
|
||||
// comment
|
||||
...,
|
||||
}
|
||||
|
||||
// Prettier master
|
||||
type T = {
|
||||
a: number,
|
||||
...
|
||||
}
|
||||
|
||||
type T = {
|
||||
[string]: number,
|
||||
...
|
||||
}
|
||||
|
||||
type T = {
|
||||
// comment
|
||||
...
|
||||
}
|
||||
```
|
||||
@@ -1416,11 +1416,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
const lastElem = getLast(n[propertiesField]);
|
||||
|
||||
const canHaveTrailingSeparator = !(
|
||||
lastElem &&
|
||||
(lastElem.type === "RestProperty" ||
|
||||
lastElem.type === "RestElement" ||
|
||||
hasNodeIgnoreComment(lastElem) ||
|
||||
n.inexact)
|
||||
n.inexact ||
|
||||
(lastElem &&
|
||||
(lastElem.type === "RestProperty" ||
|
||||
lastElem.type === "RestElement" ||
|
||||
hasNodeIgnoreComment(lastElem)))
|
||||
);
|
||||
|
||||
let content;
|
||||
|
||||
@@ -4,6 +4,141 @@ exports[`comments.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "es5"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = { /* comment */
|
||||
...};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "none"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -55,6 +190,12 @@ type Foo = {
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
@@ -113,6 +254,147 @@ type Foo = {
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js 3`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = { /* comment */
|
||||
...};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
@@ -127,7 +409,7 @@ exports[`test.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "none"
|
||||
trailingComma: "es5"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
//@flow
|
||||
@@ -136,6 +418,11 @@ type T = {
|
||||
...,
|
||||
}
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type U = { a: number, b: number, c: number, d: number, e: number, f: number, g: number, ...};
|
||||
|
||||
type V = {x: {...}, y: {x: {...}, a: number, b: number, c: number, d: number, e: number, f: number, ...}, z: {...}, foo: number, bar: {foo: number, ...}, ...};
|
||||
@@ -155,6 +442,237 @@ type T = {
|
||||
...
|
||||
};
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...
|
||||
};
|
||||
|
||||
type U = {
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
g: number,
|
||||
...
|
||||
};
|
||||
|
||||
type V = {
|
||||
x: { ... },
|
||||
y: {
|
||||
x: { ... },
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
...
|
||||
},
|
||||
z: { ... },
|
||||
foo: number,
|
||||
bar: { foo: number, ... },
|
||||
...
|
||||
};
|
||||
|
||||
function test(x: {
|
||||
foo: number,
|
||||
bar: number,
|
||||
baz: number,
|
||||
qux: nunber,
|
||||
a: number,
|
||||
b: number,
|
||||
c: { a: number, ... },
|
||||
...
|
||||
}) {
|
||||
return x;
|
||||
}
|
||||
function test(x: {
|
||||
foo: number,
|
||||
bar: number,
|
||||
baz: number,
|
||||
qux: nunber,
|
||||
a: number,
|
||||
b: number,
|
||||
c: {
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
g: number,
|
||||
h: number,
|
||||
i: number,
|
||||
...
|
||||
},
|
||||
...
|
||||
}) {
|
||||
return x;
|
||||
}
|
||||
|
||||
type W = { ... };
|
||||
type X = { ... };
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`test.js 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "none"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
//@flow
|
||||
type T = {
|
||||
a: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type U = { a: number, b: number, c: number, d: number, e: number, f: number, g: number, ...};
|
||||
|
||||
type V = {x: {...}, y: {x: {...}, a: number, b: number, c: number, d: number, e: number, f: number, ...}, z: {...}, foo: number, bar: {foo: number, ...}, ...};
|
||||
|
||||
function test(x: {foo: number, bar: number, baz: number, qux: nunber, a: number, b: number, c: {a: number, ...}, ...}) { return x; }
|
||||
function test(x: {foo: number, bar: number, baz: number, qux: nunber, a: number, b: number, c: {a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, ...}, ...}) { return x; }
|
||||
|
||||
type W = {...};
|
||||
type X = {
|
||||
...,
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
//@flow
|
||||
type T = {
|
||||
a: number,
|
||||
...
|
||||
};
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...
|
||||
};
|
||||
|
||||
type U = {
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
g: number,
|
||||
...
|
||||
};
|
||||
|
||||
type V = {
|
||||
x: { ... },
|
||||
y: {
|
||||
x: { ... },
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
...
|
||||
},
|
||||
z: { ... },
|
||||
foo: number,
|
||||
bar: { foo: number, ... },
|
||||
...
|
||||
};
|
||||
|
||||
function test(x: {
|
||||
foo: number,
|
||||
bar: number,
|
||||
baz: number,
|
||||
qux: nunber,
|
||||
a: number,
|
||||
b: number,
|
||||
c: { a: number, ... },
|
||||
...
|
||||
}) {
|
||||
return x;
|
||||
}
|
||||
function test(x: {
|
||||
foo: number,
|
||||
bar: number,
|
||||
baz: number,
|
||||
qux: nunber,
|
||||
a: number,
|
||||
b: number,
|
||||
c: {
|
||||
a: number,
|
||||
b: number,
|
||||
c: number,
|
||||
d: number,
|
||||
e: number,
|
||||
f: number,
|
||||
g: number,
|
||||
h: number,
|
||||
i: number,
|
||||
...
|
||||
},
|
||||
...
|
||||
}) {
|
||||
return x;
|
||||
}
|
||||
|
||||
type W = { ... };
|
||||
type X = { ... };
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`test.js 3`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
//@flow
|
||||
type T = {
|
||||
a: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type U = { a: number, b: number, c: number, d: number, e: number, f: number, g: number, ...};
|
||||
|
||||
type V = {x: {...}, y: {x: {...}, a: number, b: number, c: number, d: number, e: number, f: number, ...}, z: {...}, foo: number, bar: {foo: number, ...}, ...};
|
||||
|
||||
function test(x: {foo: number, bar: number, baz: number, qux: nunber, a: number, b: number, c: {a: number, ...}, ...}) { return x; }
|
||||
function test(x: {foo: number, bar: number, baz: number, qux: nunber, a: number, b: number, c: {a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, ...}, ...}) { return x; }
|
||||
|
||||
type W = {...};
|
||||
type X = {
|
||||
...,
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
//@flow
|
||||
type T = {
|
||||
a: number,
|
||||
...
|
||||
};
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...
|
||||
};
|
||||
|
||||
type U = {
|
||||
a: number,
|
||||
b: number,
|
||||
|
||||
@@ -46,6 +46,12 @@ type Foo = {
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
[string]: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["flow", "babel"], { trailingComma: "es5" });
|
||||
run_spec(__dirname, ["flow", "babel"], { trailingComma: "none" });
|
||||
run_spec(__dirname, ["flow", "babel"], { trailingComma: "all" });
|
||||
@@ -4,6 +4,11 @@ type T = {
|
||||
...,
|
||||
}
|
||||
|
||||
type I = {
|
||||
[string]: number,
|
||||
...,
|
||||
}
|
||||
|
||||
type U = { a: number, b: number, c: number, d: number, e: number, f: number, g: number, ...};
|
||||
|
||||
type V = {x: {...}, y: {x: {...}, a: number, b: number, c: number, d: number, e: number, f: number, ...}, z: {...}, foo: number, bar: {foo: number, ...}, ...};
|
||||
|
||||
Reference in new issue
Block a user