1 | const {docsUrl} = require('../utilities');
|
2 |
|
3 | module.exports = {
|
4 | meta: {
|
5 | docs: {
|
6 | description:
|
7 | 'Prevent the declaration of classes consisting only of static members.',
|
8 | category: 'Best Practices',
|
9 | recommended: false,
|
10 | uri: docsUrl('no-fully-static-classes'),
|
11 | },
|
12 | },
|
13 |
|
14 | create(context) {
|
15 | function isStaticMember(node) {
|
16 | return (
|
17 | (node.type === 'MethodDefinition' || node.type === 'ClassProperty') &&
|
18 | node.static
|
19 | );
|
20 | }
|
21 |
|
22 | function checkClass(node) {
|
23 | const members = node.body.body;
|
24 | if (
|
25 | node.superClass == null &&
|
26 | members.length &&
|
27 | members.every(isStaticMember)
|
28 | ) {
|
29 | context.report({
|
30 | node,
|
31 | message:
|
32 | 'Classes declaring only static members should be objects or named exports instead.',
|
33 | });
|
34 | }
|
35 | }
|
36 |
|
37 | return {
|
38 | ClassDeclaration: checkClass,
|
39 | ClassExpression: checkClass,
|
40 | };
|
41 | },
|
42 | };
|