From 4540f473e9e099ca61090c4fb1fc2bb4faad43d4 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 27 Feb 2017 14:18:43 -0800 Subject: [PATCH] Put short body of arrow functions on the same line (#829) By adding a group, we can avoid adding a newline if the expression fits in a single line. Fixes #800 --- src/printer.js | 2 +- tests/arrows/__snapshots__/jsfmt.spec.js.snap | 17 +++++++++++++++++ tests/arrows/short_body.js | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/arrows/short_body.js diff --git a/src/printer.js b/src/printer.js index 92123de3..0d6ec097 100644 --- a/src/printer.js +++ b/src/printer.js @@ -353,7 +353,7 @@ function genericPrintNoParens(path, options, print) { collapsed, concat([ concat(parts), - indent(options.tabWidth, concat([line, body])) + group(indent(options.tabWidth, concat([line, body]))) ]) ]), { shouldBreak: willBreak(body) } diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 86e36987..3874d7eb 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -52,3 +52,20 @@ const foo = () => { }; " `; + +exports[`short_body.js 1`] = ` +"const initializeSnapshotState = ( + testFile: Path, + update: boolean, + testPath: string, + expand: boolean, +) => new SnapshotState(testFile, update, testPath, expand); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const initializeSnapshotState = ( + testFile: Path, + update: boolean, + testPath: string, + expand: boolean +) => new SnapshotState(testFile, update, testPath, expand); +" +`; diff --git a/tests/arrows/short_body.js b/tests/arrows/short_body.js new file mode 100644 index 00000000..f7533b94 --- /dev/null +++ b/tests/arrows/short_body.js @@ -0,0 +1,6 @@ +const initializeSnapshotState = ( + testFile: Path, + update: boolean, + testPath: string, + expand: boolean, +) => new SnapshotState(testFile, update, testPath, expand);