X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=eslint%2Flib%2Frules%2Fid-length.js;h=4df081ff9fe4f85011848c324784ce8090246d67;hb=6f036462704d9ce418f40ac7bd6ee34d916fa3b5;hp=a68873ac06289b0b3c28b67a04d0ee064c2756c4;hpb=a4a2572412fc0fce7ee3862a533144d797a86f44;p=pve-eslint.git diff --git a/eslint/lib/rules/id-length.js b/eslint/lib/rules/id-length.js index a68873a..4df081f 100644 --- a/eslint/lib/rules/id-length.js +++ b/eslint/lib/rules/id-length.js @@ -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 }