Skip to content

Commit

Permalink
Add test for static blocks (sindresorhus#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and manovotny committed Sep 21, 2021
1 parent 5e51b04 commit cb4aeaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion rules/no-static-only-class.js
Expand Up @@ -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;
}
Expand Down
19 changes: 18 additions & 1 deletion test/no-static-only-class.mjs
Expand Up @@ -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() {}; }',
Expand Down Expand Up @@ -91,6 +94,8 @@ test.typescript({
static a = 1;
}
`,
// Static block
'class A { static {}; }',
],
invalid: [
{
Expand Down Expand Up @@ -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() {} }',
Expand Down

0 comments on commit cb4aeaf

Please sign in to comment.