Fix printing separator in objects with prettier-ignore (#3448)

master
Lucas Duailibe 2017-12-10 02:57:42 -02:00 committed by GitHub
parent 69f05e42c9
commit dbf22eb41a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 176 additions and 3 deletions

View File

@ -975,9 +975,13 @@ function genericPrintNoParens(path, options, print, args) {
let separatorParts = [];
const props = propsAndLoc.sort((a, b) => a.loc - b.loc).map(prop => {
const result = concat(separatorParts.concat(group(prop.printed)));
separatorParts = hasNodeIgnoreComment(prop.node)
? [line]
: [separator, line];
separatorParts = [separator, line];
if (
hasNodeIgnoreComment(prop.node) &&
prop.node.type === "TSPropertySignature"
) {
separatorParts.shift();
}
if (util.isNextLineEmpty(options.originalText, prop.node)) {
separatorParts.push(hardline);
}

View File

@ -64,6 +64,12 @@ function a() {
)
}
}
const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: 'lights',
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function a() {
// prettier-ignore
@ -128,4 +134,10 @@ function a() {
}
}
const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: "lights"
};
`;

View File

@ -61,3 +61,9 @@ function a() {
)
}
}
const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: 'lights',
};

View File

@ -9,6 +9,15 @@ abstract interface I {}
`;
exports[`abstract.ts 2`] = `
abstract interface I {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
abstract interface I {}
`;
exports[`comments.js 1`] = `
interface ScreenObject {
// I make things weird.
@ -22,18 +31,33 @@ interface ScreenObject {
`;
exports[`comments.js 2`] = `
interface ScreenObject {
// I make things weird.
at(point: Point): Screen | undefined;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
interface ScreenObject {
// I make things weird.
at(point: Point): Screen | undefined
}
`;
exports[`ignore.js 1`] = `
interface Interface {
// prettier-ignore
prop: type
// prettier-ignore
prop: type;
prop: type;
}
// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
interface Interface {
@ -41,12 +65,47 @@ interface Interface {
prop: type
// prettier-ignore
prop: type;
prop: type;
}
// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type;
}
`;
exports[`ignore.js 2`] = `
interface Interface {
// prettier-ignore
prop: type
// prettier-ignore
prop: type;
prop: type;
}
// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
interface Interface {
// prettier-ignore
prop: type
// prettier-ignore
prop: type;
prop: type
}
// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type
}
`;
@ -102,6 +161,57 @@ export interface ThirdVeryLongAndBoringInterfaceName
`;
exports[`long-extends.ts 2`] = `
export interface I extends A, B, C {
c: string;
}
export interface ThirdVeryLongAndBoringInterfaceName extends ALongAndBoringInterfaceName {
c: string;
}
export interface ThirdVeryLongAndBoringInterfaceName extends ALongAndBoringInterfaceName, AnotherLongAndBoringInterfaceName {
c: string;
}
export interface ThirdVeryLongAndBoringInterfaceName extends AVeryLongAndBoringInterfaceName, AnotherVeryLongAndBoringInterfaceName {
c: string;
}
export interface ThirdVeryLongAndBoringInterfaceName extends A_AVeryLongAndBoringInterfaceName, B_AVeryLongAndBoringInterfaceName, C_AVeryLongAndBoringInterfaceName {
c: string;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export interface I extends A, B, C {
c: string
}
export interface ThirdVeryLongAndBoringInterfaceName
extends ALongAndBoringInterfaceName {
c: string
}
export interface ThirdVeryLongAndBoringInterfaceName
extends ALongAndBoringInterfaceName,
AnotherLongAndBoringInterfaceName {
c: string
}
export interface ThirdVeryLongAndBoringInterfaceName
extends AVeryLongAndBoringInterfaceName,
AnotherVeryLongAndBoringInterfaceName {
c: string
}
export interface ThirdVeryLongAndBoringInterfaceName
extends A_AVeryLongAndBoringInterfaceName,
B_AVeryLongAndBoringInterfaceName,
C_AVeryLongAndBoringInterfaceName {
c: string
}
`;
exports[`separator.ts 1`] = `
declare module 'selenium-webdriver' {
export const until: {
@ -139,3 +249,41 @@ interface Test {
}
`;
exports[`separator.ts 2`] = `
declare module 'selenium-webdriver' {
export const until: {
ableToSwitchToFrame(frame: number | WebElement | By): Condition<boolean>;
alertIsPresent(): Condition<Alert>;
};
}
export interface Edge {
cursor: {};
node: {
id: {};
};
}
interface Test { one: string, two: any[] }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare module "selenium-webdriver" {
export const until: {
ableToSwitchToFrame(frame: number | WebElement | By): Condition<boolean>
alertIsPresent(): Condition<Alert>
}
}
export interface Edge {
cursor: {}
node: {
id: {}
}
}
interface Test {
one: string
two: any[]
}
`;

View File

@ -3,10 +3,12 @@ interface Interface {
prop: type
// prettier-ignore
prop: type;
prop: type;
}
// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type
}

View File

@ -1 +1,2 @@
run_spec(__dirname, ["typescript"]);
run_spec(__dirname, ["typescript"], { semi: false });