]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-empty-static-block.js
import 8.41.0 source
[pve-eslint.git] / eslint / tests / lib / rules / no-empty-static-block.js
diff --git a/eslint/tests/lib/rules/no-empty-static-block.js b/eslint/tests/lib/rules/no-empty-static-block.js
new file mode 100644 (file)
index 0000000..592c840
--- /dev/null
@@ -0,0 +1,51 @@
+/**
+ * @fileoverview Tests for no-empty-static-block rule.
+ * @author Sosuke Suzuki
+ */
+"use strict";
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require("../../../lib/rules/no-empty-static-block"),
+    { RuleTester } = require("../../../lib/rule-tester");
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+const ruleTester = new RuleTester({
+    parserOptions: { ecmaVersion: 2022 }
+});
+
+ruleTester.run("no-empty-static-block", rule, {
+    valid: [
+        "class Foo { static { bar(); } }",
+        "class Foo { static { /* comments */ } }",
+        "class Foo { static {\n// comment\n} }",
+        "class Foo { static { bar(); } static { bar(); } }"
+    ],
+    invalid: [
+        {
+            code: "class Foo { static {} }",
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "class Foo { static { } }",
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "class Foo { static { \n\n } }",
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "class Foo { static { bar(); } static {} }",
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "class Foo { static // comment\n {} }",
+            errors: [{ messageId: "unexpected" }]
+        }
+    ]
+});