]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/rules/id-length.js
import 7.12.1 upstream release
[pve-eslint.git] / eslint / lib / rules / id-length.js
index a68873ac06289b0b3c28b67a04d0ee064c2756c4..4df081ff9fe4f85011848c324784ce8090246d67 100644 (file)
@@ -39,6 +39,13 @@ module.exports = {
                             type: "string"
                         }
                     },
+                    exceptionPatterns: {
+                        type: "array",
+                        uniqueItems: true,
+                        items: {
+                            type: "string"
+                        }
+                    },
                     properties: {
                         enum: ["always", "never"]
                     }
@@ -57,14 +64,20 @@ module.exports = {
         const minLength = typeof options.min !== "undefined" ? options.min : 2;
         const maxLength = typeof options.max !== "undefined" ? options.max : Infinity;
         const properties = options.properties !== "never";
-        const exceptions = (options.exceptions ? options.exceptions : [])
-            .reduce((obj, item) => {
-                obj[item] = true;
-
-                return obj;
-            }, {});
+        const exceptions = new Set(options.exceptions);
+        const exceptionPatterns = (options.exceptionPatterns || []).map(pattern => new RegExp(pattern, "u"));
         const reportedNode = new Set();
 
+        /**
+         * Checks if a string matches the provided exception patterns
+         * @param {string} name The string to check.
+         * @returns {boolean} if the string is a match
+         * @private
+         */
+        function matchesExceptionPattern(name) {
+            return exceptionPatterns.some(pattern => pattern.test(name));
+        }
+
         const SUPPORTED_EXPRESSIONS = {
             MemberExpression: properties && function(parent) {
                 return !parent.computed && (
@@ -112,7 +125,7 @@ module.exports = {
                 const isShort = name.length < minLength;
                 const isLong = name.length > maxLength;
 
-                if (!(isShort || isLong) || exceptions[name]) {
+                if (!(isShort || isLong) || exceptions.has(name) || matchesExceptionPattern(name)) {
                     return; // Nothing to report
                 }