Fix trailing whitespace (#300)
In the printer, remove trailing whitespace except for template literals Fixes #222master
parent
38c8d8cd0f
commit
f79e838095
14
src/pp.js
14
src/pp.js
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
\`
|
||||
|
||||
|
||||
\` + \`
|
||||
|
||||
|
||||
\`;
|
||||
"
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname);
|
|
@ -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
|
||||
`
|
||||
|
||||
|
||||
` + `
|
||||
|
||||
|
||||
`;
|
Loading…
Reference in New Issue