]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-empty.js
import 8.41.0 source
[pve-eslint.git] / eslint / tests / lib / rules / no-empty.js
index 98651a41256d42186d1b90f86e21cefe2adaaf67..812aa8de994f5968684e42949213ec74c7773e1c 100644 (file)
@@ -44,36 +44,187 @@ ruleTester.run("no-empty", rule, {
         { code: "try { foo(); } catch (ex) {} finally { bar(); }", options: [{ allowEmptyCatch: true }] }
     ],
     invalid: [
-        { code: "try {} catch (ex) {throw ex}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "try { foo() } catch (ex) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "try { foo() } catch (ex) {throw ex} finally {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "if (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "while (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "for (;foo;) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
-        { code: "switch(foo) {}", errors: [{ messageId: "unexpected", data: { type: "switch" }, type: "SwitchStatement" }] },
+        {
+            code: "try {} catch (ex) {throw ex}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "try { /* empty */ } catch (ex) {throw ex}"
+                }]
+            }]
+        },
+        {
+            code: "try { foo() } catch (ex) {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "try { foo() } catch (ex) { /* empty */ }"
+                }]
+            }]
+        },
+        {
+            code: "try { foo() } catch (ex) {throw ex} finally {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "try { foo() } catch (ex) {throw ex} finally { /* empty */ }"
+                }]
+            }]
+        },
+        {
+            code: "if (foo) {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "if (foo) { /* empty */ }"
+                }]
+            }]
+        },
+        {
+            code: "while (foo) {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "while (foo) { /* empty */ }"
+                }]
+            }]
+        },
+        {
+            code: "for (;foo;) {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "for (;foo;) { /* empty */ }"
+                }]
+            }]
+        },
+        {
+            code: "switch(foo) {}",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "switch" },
+                type: "SwitchStatement",
+                suggestions: null
+            }]
+        },
+        {
+            code: "switch (foo) { /* empty */ }",
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "switch" },
+                type: "SwitchStatement",
+                suggestions: null
+            }]
+        },
         {
             code: "try {} catch (ex) {}",
             options: [{ allowEmptyCatch: true }],
-            errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }]
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "try { /* empty */ } catch (ex) {}"
+                }]
+            }]
         },
         {
             code: "try { foo(); } catch (ex) {} finally {}",
             options: [{ allowEmptyCatch: true }],
-            errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }]
+            errors: [{
+                messageId: "unexpected",
+                data: { type: "block" },
+                type: "BlockStatement",
+                suggestions: [{
+                    messageId: "suggestComment",
+                    data: { type: "block" },
+                    output: "try { foo(); } catch (ex) {} finally { /* empty */ }"
+                }]
+            }]
         },
         {
             code: "try {} catch (ex) {} finally {}",
             options: [{ allowEmptyCatch: true }],
             errors: [
-                { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" },
-                { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }
+                {
+                    messageId: "unexpected",
+                    data: { type: "block" },
+                    type: "BlockStatement",
+                    suggestions: [
+                        {
+                            messageId: "suggestComment",
+                            data: { type: "block" },
+                            output: "try { /* empty */ } catch (ex) {} finally {}"
+                        }
+                    ]
+                },
+                {
+                    messageId: "unexpected",
+                    data: { type: "block" },
+                    type: "BlockStatement",
+                    suggestions: [
+                        {
+                            messageId: "suggestComment",
+                            data: { type: "block" },
+                            output: "try {} catch (ex) {} finally { /* empty */ }"
+                        }
+                    ]
+                }
             ]
         },
         {
             code: "try { foo(); } catch (ex) {} finally {}",
             errors: [
-                { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" },
-                { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }
+                {
+                    messageId: "unexpected",
+                    data: { type: "block" },
+                    type: "BlockStatement",
+                    suggestions: [
+                        {
+                            messageId: "suggestComment",
+                            data: { type: "block" },
+                            output: "try { foo(); } catch (ex) { /* empty */ } finally {}"
+                        }
+                    ]
+                },
+                {
+                    messageId: "unexpected",
+                    data: { type: "block" },
+                    type: "BlockStatement",
+                    suggestions: [
+                        {
+                            messageId: "suggestComment",
+                            data: { type: "block" },
+                            output: "try { foo(); } catch (ex) {} finally { /* empty */ }"
+                        }
+                    ]
+                }
             ]
         }
     ]