Fix trailing whitespace (#300)

In the printer, remove trailing whitespace except for template literals

Fixes #222
master
Christopher Chedeau 2017-01-18 12:38:33 -08:00 committed by James Long
parent 38c8d8cd0f
commit f79e838095
12 changed files with 73 additions and 38 deletions

View File

@ -352,19 +352,17 @@ function print(w, doc) {
}
case MODE_BREAK:
if (out.length > 0) {
const lastString = out[out.length - 1];
if (lastString.match(/^\s*\n\s*$/)) {
out[out.length - 1] = "\n";
}
}
if (doc.literal) {
out.push("\n");
pos = 0;
} else {
if (out.length > 0) {
// Trim whitespace at the end of line
out[out.length - 1] = out[out.length - 1]
.replace(/[^\S\n]*$/, '');
}
out.push("\n" + " ".repeat(ind));
pos = ind;

View File

@ -0,0 +1,26 @@
exports[`test trailing.js 1`] = `
"export type Result<T, V> = | { kind: \"not-test-editor1\" } | { kind: \"not-test-editor2\" };
// Note: there are trailing whitespace in this file
\`
\` + \`
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export type Result<T, V> =
| { kind: \"not-test-editor1\" }
| { kind: \"not-test-editor2\" };
// Note: there are trailing whitespace in this file
\`
\` + \`
\`;
"
`;

View File

@ -0,0 +1 @@
run_spec(__dirname);

View File

@ -0,0 +1,10 @@
export type Result<T, V> = | { kind: "not-test-editor1" } | { kind: "not-test-editor2" };
// Note: there are trailing whitespace in this file
`
` + `
`;