Skip to content
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 printing separator in objects with prettier-ignore #3448

Merged
merged 2 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,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);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ignore/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function a() {
)
}
}

const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: 'lights',
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function a() {
// prettier-ignore
Expand Down Expand Up @@ -128,4 +134,10 @@ function a() {
}
}

const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: "lights"
};

`;
6 changes: 6 additions & 0 deletions tests/ignore/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ function a() {
)
}
}

const response = {
// prettier-ignore
'_text': 'Turn on the lights',
intent: 'lights',
};
148 changes: 148 additions & 0 deletions tests/typescript_interface/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,31 +31,81 @@ 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 {
// prettier-ignore
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
}

`;
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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[]
}

`;
2 changes: 2 additions & 0 deletions tests/typescript_interface/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ interface Interface {
prop: type
// prettier-ignore
prop: type;
prop: type;
}

// Last element
interface Interface {
// prettier-ignore
prop: type
prop: type
}
1 change: 1 addition & 0 deletions tests/typescript_interface/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
run_spec(__dirname, ["typescript"]);
run_spec(__dirname, ["typescript"], { semi: false });