node_modules/eslint/lib/rules/complexity.js in immosquare-cleaner-0.1.47 vs node_modules/eslint/lib/rules/complexity.js in immosquare-cleaner-0.1.48

- old
+ new

@@ -43,10 +43,13 @@ minimum: 0 }, max: { type: "integer", minimum: 0 + }, + variant: { + enum: ["classic", "modified"] } }, additionalProperties: false } ] @@ -59,20 +62,26 @@ }, create(context) { const option = context.options[0]; let THRESHOLD = 20; + let VARIANT = "classic"; - if ( - typeof option === "object" && - (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) - ) { - THRESHOLD = option.maximum || option.max; + if (typeof option === "object") { + if (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) { + THRESHOLD = option.maximum || option.max; + } + + if (Object.hasOwn(option, "variant")) { + VARIANT = option.variant; + } } else if (typeof option === "number") { THRESHOLD = option; } + const IS_MODIFIED_COMPLEXITY = VARIANT === "modified"; + //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- // Using a stack to store complexity per code path @@ -110,10 +119,11 @@ WhileStatement: increaseComplexity, DoWhileStatement: increaseComplexity, AssignmentPattern: increaseComplexity, // Avoid `default` - "SwitchCase[test]": increaseComplexity, + "SwitchCase[test]": () => IS_MODIFIED_COMPLEXITY || increaseComplexity(), + SwitchStatement: () => IS_MODIFIED_COMPLEXITY && increaseComplexity(), // Logical assignment operators have short-circuiting behavior AssignmentExpression(node) { if (astUtils.isLogicalAssignmentOperator(node.operator)) { increaseComplexity();