forked from eslint/eslint
/
no-empty-static-block.js
51 lines (46 loc) · 1.54 KB
/
no-empty-static-block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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" }]
}
]
});