Skip to content

Commit

Permalink
Remove trailing whitespace (#1259)
Browse files Browse the repository at this point in the history
In #1257, I discovered that if there's a `""` doc at the end, it's not going to trim the previous one correctly. It also happens to fix a few existing things.
  • Loading branch information
vjeux committed Apr 14, 2017
1 parent 61183f8 commit 9d616fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/doc-printer.js
Expand Up @@ -267,6 +267,13 @@ function printDocToString(doc, options) {
} else {
if (out.length > 0) {
// Trim whitespace at the end of line
while (
out.length > 0 &&
out[out.length - 1].match(/^[^\S\n]*$/)
) {
out.pop();
}

out[out.length - 1] = out[out.length - 1].replace(
/[^\S\n]*$/,
""
Expand Down
Expand Up @@ -507,7 +507,7 @@ function f(x: string): void {
return;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): number
function f(x: string): number
function f(x: string): void {
return;
}
Expand All @@ -520,7 +520,7 @@ function f(x: string): number {
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): void
function f(x: string): void
function f(x: string): number {
return 0;
}
Expand All @@ -533,7 +533,7 @@ function f(x: string): void {
return;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f(x: string): void
function f(x: string): void
function f(x: string): void {
return;
}
Expand All @@ -553,14 +553,14 @@ function fn5(x: string, ...y: any[], z: string);
function fn5() { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Function overload signature with optional parameter followed by non-optional parameter
function fn4a(x?: number, y: string)
function fn4a(x?: number, y: string)
function fn4a() {}
function fn4b(n: string, x?: number, y: string)
function fn4b(n: string, x?: number, y: string)
function fn4b() {}
//Function overload signature with rest param followed by non-optional parameter
function fn5(x: string, ...y: any[], z: string)
function fn5(x: string, ...y: any[], z: string)
function fn5() {}
`;
Expand Down
Expand Up @@ -212,7 +212,7 @@ var y = foo([undefined]);
y = [""];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@noImplicitAny: true
declare function foo<T extends [any]>(x: T): T
declare function foo<T extends [any]>(x: T): T
var y = foo([undefined]);
y = [""];
Expand Down

0 comments on commit 9d616fc

Please sign in to comment.