From cb4aeaff92705fe06117ff6b7cc22163991729bb Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 11:25:47 +0800 Subject: [PATCH] Add test for static blocks (#1513) --- rules/no-static-only-class.js | 1 - test/no-static-only-class.mjs | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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; } diff --git a/test/no-static-only-class.mjs b/test/no-static-only-class.mjs index 564cbe2f22..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() {}; }', @@ -91,6 +94,8 @@ test.typescript({ static a = 1; } `, + // Static block + 'class A { static {}; }', ], invalid: [ { @@ -201,7 +206,19 @@ test.typescript({ }); test.babel({ - valid: [], + testerOptions: { + parserOptions: { + babelOptions: { + parserOpts: { + plugins: ['classStaticBlock'], + }, + }, + }, + }, + valid: [ + // Static block + 'class A2 { static {}; }', + ], invalid: [ { code: 'class A { static a() {} }',