Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for static blocks #1513

Merged
merged 3 commits into from Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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