Repository: jlongster/prettier (js)

Issue:
Empty switch: extraneous blank line
Input:

```js
switch(1){}
```

Output:

```js
switch (1) {

}
```

Expected:

```js
switch (1) {
}
```

(just like empty `if`)

Do we care? ¯\\\_(ツ)\_/¯

https://jlongster.github.io/prettier/#%7B%22content%22%3A%22switch(1)%7B%7D%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22doc%22%3Afalse%7D%7D

Pull request description:
Empty switch should not have an empty line
Fixes #368

Patch:
diff --git a/src/printer.js b/src/printer.js
index 753e1436d..1f7f503d4 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -971,10 +971,10 @@ function genericPrintNoParens(path, options, print) {
         "switch (",
         path.call(print, "discriminant"),
         ") {",
-        indent(
+        n.cases.length > 0 ? indent(
           options.tabWidth,
           concat([ hardline, join(hardline, path.map(print, "cases")) ])
-        ),
+        ) : "",
         hardline,
         "}"
       ]);


Test patch:
diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap
index 0005e88a0..e8273fdde 100644
--- a/tests/switch/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap
@@ -1,9 +1,12 @@
 exports[`test empty_switch.js 1`] = `
 "switch (1) { default:; }
+switch (1) {}
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 switch (1) {
   default:
 }
+switch (1) {
+}
 "
 `;
 
diff --git a/tests/switch/empty_switch.js b/tests/switch/empty_switch.js
index b91bfe9d4..99b951444 100644
--- a/tests/switch/empty_switch.js
+++ b/tests/switch/empty_switch.js
@@ -1,1 +1,2 @@
 switch (1) { default:; }
+switch (1) {}