Skip to content

Commit

Permalink
Fix empty file format (#7921)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 1, 2020
1 parent e199e68 commit 22e3004
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/language-js/printer-estree.js
Expand Up @@ -494,7 +494,10 @@ function printPathNoParens(path, options, print, args) {
);

// Only force a trailing newline if there were any contents.
if (n.body.length || n.comments) {
if (
!n.body.every(({ type }) => type === "EmptyStatement") ||
n.comments
) {
parts.push(hardline);
}

Expand Down
28 changes: 27 additions & 1 deletion tests/js_empty/__snapshots__/jsfmt.spec.js.snap
@@ -1,15 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`semicolon.js 1`] = `
exports[`empty.js 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
=====================================output=====================================
================================================================================
`;

exports[`many-semicolons.js 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
;;
;
=====================================output=====================================
================================================================================
`;

exports[`semicolon.js 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
;
=====================================output=====================================
================================================================================
`;
1 change: 1 addition & 0 deletions tests/js_empty/empty.js
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions tests/js_empty/many-semicolons.js
@@ -0,0 +1,2 @@
;;
;
1 change: 0 additions & 1 deletion tests_config/run_spec.js
Expand Up @@ -34,7 +34,6 @@ const unstableTests = new Map(
"html_angular/attributes.component.html",
(options) => options.printWidth === 1,
],
"js_empty/semicolon.js",
"markdown_footnoteDefinition/multiline.md",
"markdown_spec/example-234.md",
"markdown_spec/example-235.md",
Expand Down

0 comments on commit 22e3004

Please sign in to comment.