|
| 1 | +/** |
| 2 | + * @fileoverview Tests for no-empty-static-block rule. |
| 3 | + * @author Sosuke Suzuki |
| 4 | + */ |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +//------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +//------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const rule = require("../../../lib/rules/no-empty-static-block"), |
| 12 | + { RuleTester } = require("../../../lib/rule-tester"); |
| 13 | + |
| 14 | +//------------------------------------------------------------------------------ |
| 15 | +// Tests |
| 16 | +//------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +const ruleTester = new RuleTester({ |
| 19 | + parserOptions: { ecmaVersion: 2022 } |
| 20 | +}); |
| 21 | + |
| 22 | +ruleTester.run("no-empty-static-block", rule, { |
| 23 | + valid: [ |
| 24 | + "class Foo { static { bar(); } }", |
| 25 | + "class Foo { static { /* comments */ } }", |
| 26 | + "class Foo { static {\n// comment\n} }", |
| 27 | + "class Foo { static { bar(); } static { bar(); } }" |
| 28 | + ], |
| 29 | + invalid: [ |
| 30 | + { |
| 31 | + code: "class Foo { static {} }", |
| 32 | + errors: [{ messageId: "unexpected" }] |
| 33 | + }, |
| 34 | + { |
| 35 | + code: "class Foo { static { } }", |
| 36 | + errors: [{ messageId: "unexpected" }] |
| 37 | + }, |
| 38 | + { |
| 39 | + code: "class Foo { static { \n\n } }", |
| 40 | + errors: [{ messageId: "unexpected" }] |
| 41 | + }, |
| 42 | + { |
| 43 | + code: "class Foo { static { bar(); } static {} }", |
| 44 | + errors: [{ messageId: "unexpected" }] |
| 45 | + }, |
| 46 | + { |
| 47 | + code: "class Foo { static // comment\n {} }", |
| 48 | + errors: [{ messageId: "unexpected" }] |
| 49 | + } |
| 50 | + ] |
| 51 | +}); |
0 commit comments