From 27abd5249ac9ede2874ac7e0af0e77f51b0f9408 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 10:13:49 +0800 Subject: [PATCH 1/3] Add test for static blocks --- test/no-static-only-class.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/no-static-only-class.mjs b/test/no-static-only-class.mjs index 564cbe2f22..b6b054bac7 100644 --- a/test/no-static-only-class.mjs +++ b/test/no-static-only-class.mjs @@ -91,6 +91,8 @@ test.typescript({ static a = 1; } `, + // Static block + 'class A { static {}; }', ], invalid: [ { @@ -201,7 +203,19 @@ test.typescript({ }); test.babel({ - valid: [], + testerOptions: { + parserOptions: { + babelOptions: { + parserOpts: { + plugins: ['classStaticBlock'], + }, + }, + }, + }, + valid: [ + // Static block + 'class A2 { static {}; }', + ], invalid: [ { code: 'class A { static a() {} }', From 7b83149251f0644b7b8755fcc721a8862aa65ca7 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 10:14:51 +0800 Subject: [PATCH 2/3] Update comment --- rules/no-static-only-class.js | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/no-static-only-class.js b/rules/no-static-only-class.js index cb12f9c484..7fc31b55c9 100644 --- a/rules/no-static-only-class.js +++ b/rules/no-static-only-class.js @@ -40,7 +40,6 @@ function isStaticMember(node) { } = node; // Avoid matching unexpected node. For example: https://github.com/tc39/proposal-class-static-block - /* istanbul ignore next */ if (!isPropertyDefinition(node) && !isMethodDefinition(node)) { return false; } From 1205dda512f46d8a8f51a3acf3203e7dc8ec49c7 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 10:16:07 +0800 Subject: [PATCH 3/3] Add todo --- test/no-static-only-class.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/no-static-only-class.mjs b/test/no-static-only-class.mjs index b6b054bac7..1e4191da32 100644 --- a/test/no-static-only-class.mjs +++ b/test/no-static-only-class.mjs @@ -16,6 +16,9 @@ test.snapshot({ 'class A { constructor() {} }', 'class A { get a() {} }', 'class A { set a(value) {} }', + // TODO: enable this test when ESLint support `StaticBlock` + // Static block + // 'class A2 { static {}; }', ], invalid: [ 'class A { static a() {}; }',