]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/rules/max-classes-per-file.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / rules / max-classes-per-file.js
index bb48a546e95c6055ec2f6b0a95a5fbb68bad7504..3d26108a71504ace6b7ff9e1a76a05cec95a6d11 100644 (file)
@@ -19,15 +19,31 @@ module.exports = {
 
         docs: {
             description: "enforce a maximum number of classes per file",
-            category: "Best Practices",
             recommended: false,
             url: "https://eslint.org/docs/rules/max-classes-per-file"
         },
 
         schema: [
             {
-                type: "integer",
-                minimum: 1
+                oneOf: [
+                    {
+                        type: "integer",
+                        minimum: 1
+                    },
+                    {
+                        type: "object",
+                        properties: {
+                            ignoreExpressions: {
+                                type: "boolean"
+                            },
+                            max: {
+                                type: "integer",
+                                minimum: 1
+                            }
+                        },
+                        additionalProperties: false
+                    }
+                ]
             }
         ],
 
@@ -36,8 +52,10 @@ module.exports = {
         }
     },
     create(context) {
-
-        const maxClasses = context.options[0] || 1;
+        const [option = {}] = context.options;
+        const [ignoreExpressions, max] = typeof option === "number"
+            ? [false, option || 1]
+            : [option.ignoreExpressions, option.max || 1];
 
         let classCount = 0;
 
@@ -46,19 +64,24 @@ module.exports = {
                 classCount = 0;
             },
             "Program:exit"(node) {
-                if (classCount > maxClasses) {
+                if (classCount > max) {
                     context.report({
                         node,
                         messageId: "maximumExceeded",
                         data: {
                             classCount,
-                            max: maxClasses
+                            max
                         }
                     });
                 }
             },
-            "ClassDeclaration, ClassExpression"() {
+            "ClassDeclaration"() {
                 classCount++;
+            },
+            "ClassExpression"() {
+                if (!ignoreExpressions) {
+                    classCount++;
+                }
             }
         };
     }