Fix adding trailing comma in TS tuples (#6199)

master
Lucas Duailibe 2019-06-07 11:18:42 -03:00 committed by GitHub
parent f070f00385
commit a90adf4753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 1 deletions

View File

@ -2487,7 +2487,7 @@ function printPathNoParens(path, options, print, args) {
printArrayItems(path, options, typesField, print)
])
),
ifBreak(shouldPrintComma(options) ? "," : ""),
ifBreak(shouldPrintComma(options, "all") ? "," : ""),
comments.printDanglingComments(path, options, /* sameIndent */ true),
softline,
"]"

View File

@ -44,6 +44,47 @@ exports[`trailing-comma.ts 2`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================
export interface ShopQueryResult {
chic: boolean;
location: number[];
menus: Menu[];
openingDays: number[];
closingDays: [
{
from: string,
to: string,
}, // <== this one
];
shop: string;
distance: number;
}
=====================================output=====================================
export interface ShopQueryResult {
chic: boolean;
location: number[];
menus: Menu[];
openingDays: number[];
closingDays: [
{
from: string;
to: string;
} // <== this one
];
shop: string;
distance: number;
}
================================================================================
`;
exports[`trailing-comma.ts 3`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
@ -114,6 +155,36 @@ exports[`tuple.ts 2`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================
export type SCMRawResource = [
number /*handle*/,
string /*resourceUri*/,
modes.Command /*command*/,
string[] /*icons: light, dark*/,
boolean /*strike through*/,
boolean /*faded*/
];
=====================================output=====================================
export type SCMRawResource = [
number /*handle*/,
string /*resourceUri*/,
modes.Command /*command*/,
string[] /*icons: light, dark*/,
boolean /*strike through*/,
boolean /*faded*/
];
================================================================================
`;
exports[`tuple.ts 3`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================

View File

@ -1,2 +1,3 @@
run_spec(__dirname, ["typescript"]);
run_spec(__dirname, ["typescript"], { trailingComma: "es5" });
run_spec(__dirname, ["typescript"], { trailingComma: "all" });