From 90e8b13e867bcb6423c736b068a06169b8892fc0 Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Thu, 7 Dec 2017 03:28:29 -0200 Subject: [PATCH] Ignore whitespace in docblock right after /** (#3430) --- index.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 21 +++++++++++++++++++ .../trailing-spaces-first-line.js | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/insert-pragma/trailing-spaces-first-line.js 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. + */