Search in sources :

Example 1 with CognitiveComplexity

use of org.sonar.commonruleengine.CognitiveComplexity in project sonar-go by SonarSource.

the class FunctionCognitiveComplexityCheck method visitNode.

@Override
public void visitNode(UastNode node) {
    nestedFunctionLevel++;
    if (nestedFunctionLevel != 1) {
        return;
    }
    FunctionLike functionNode = FunctionLike.from(node);
    if (functionNode == null) {
        return;
    }
    CognitiveComplexity complexity = CognitiveComplexity.calculateFunctionComplexity(functionNode.node());
    if (complexity.value() > maxComplexity) {
        String message = "Refactor this function to reduce its Cognitive Complexity from " + complexity.value() + " to the " + maxComplexity + " allowed.";
        int effortToFix = complexity.value() - maxComplexity;
        reportIssue(functionNode.name(), functionNode.name(), message, effortToFix, complexity.secondaryLocations());
    }
}
Also used : CognitiveComplexity(org.sonar.commonruleengine.CognitiveComplexity) FunctionLike(org.sonar.uast.helpers.FunctionLike)

Aggregations

CognitiveComplexity (org.sonar.commonruleengine.CognitiveComplexity)1 FunctionLike (org.sonar.uast.helpers.FunctionLike)1