diff --git a/index.js b/index.js index cfb6a929..23f0fbfd 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ function formatWithCursor(text, opts, addAlignmentSize) { const pragmas = Object.assign({ format: "" }, parsedDocblock.pragmas); const newDocblock = docblock.print({ pragmas, - comments: parsedDocblock.comments.replace(/^(\r?\n)+/, "") // remove leading newlines + comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines }); const strippedText = docblock.strip(text); const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n"; diff --git a/tests/insert-pragma/__snapshots__/jsfmt.spec.js.snap b/tests/insert-pragma/__snapshots__/jsfmt.spec.js.snap index 7caac5ce..38f670e2 100644 --- a/tests/insert-pragma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/insert-pragma/__snapshots__/jsfmt.spec.js.snap @@ -85,3 +85,24 @@ function foo(bar) { } `; + +exports[`trailing-spaces-first-line.js 1`] = ` +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + */ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + * + * @format + */ + +`; diff --git a/tests/insert-pragma/trailing-spaces-first-line.js b/tests/insert-pragma/trailing-spaces-first-line.js new file mode 100644 index 00000000..ad5e82e9 --- /dev/null +++ b/tests/insert-pragma/trailing-spaces-first-line.js @@ -0,0 +1,7 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + */