Skip to content

Commit

Permalink
Put short body of arrow functions on the same line
Browse files Browse the repository at this point in the history
By adding a group, we can avoid adding a newline if the expression fits in a single line.

Fixes prettier#800
  • Loading branch information
vjeux committed Feb 27, 2017
1 parent 443a5d6 commit 7385033
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
17 changes: 17 additions & 0 deletions tests/arrows/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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);
"
`;
6 changes: 6 additions & 0 deletions tests/arrows/short_body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const initializeSnapshotState = (
testFile: Path,
update: boolean,
testPath: string,
expand: boolean,
) => new SnapshotState(testFile, update, testPath, expand);

0 comments on commit 7385033

Please sign in to comment.