Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty file format #7921

Merged
merged 1 commit into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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