Trim trailing whitespace from comments, closes #2422 (#2494)

master
Lucas Azzola 2017-07-16 17:45:27 +10:00 committed by GitHub
parent 123d350524
commit 00d9aa208e
3 changed files with 23 additions and 3 deletions

View File

@ -831,7 +831,7 @@ function printComment(commentPath, options) {
switch (comment.type || comment.kind) { switch (comment.type || comment.kind) {
case "Comment": case "Comment":
return "#" + comment.value; return "#" + comment.value.trimRight();
case "CommentBlock": case "CommentBlock":
case "Block": case "Block":
return "/*" + comment.value + "*/"; return "/*" + comment.value + "*/";
@ -839,9 +839,9 @@ function printComment(commentPath, options) {
case "Line": case "Line":
// Print shebangs with the proper comment characters // Print shebangs with the proper comment characters
if (options.originalText.slice(util.locStart(comment)).startsWith("#!")) { if (options.originalText.slice(util.locStart(comment)).startsWith("#!")) {
return "#!" + comment.value; return "#!" + comment.value.trimRight();
} }
return "//" + comment.value; return "//" + comment.value.trimRight();
default: default:
throw new Error("Not a comment: " + JSON.stringify(comment)); throw new Error("Not a comment: " + JSON.stringify(comment));
} }

View File

@ -1249,6 +1249,21 @@ d //comment
`; `;
exports[`trailing_space.js 1`] = `
#!/there/is-space-here->
// Do not trim trailing whitespace from this source file!
// There is some space here ->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/there/is-space-here->
// Do not trim trailing whitespace from this source file!
// There is some space here ->
`;
exports[`try.js 1`] = ` exports[`try.js 1`] = `
// comment 1 // comment 1
try { try {

View File

@ -0,0 +1,5 @@
#!/there/is-space-here->
// Do not trim trailing whitespace from this source file!
// There is some space here ->