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());
}
}
Aggregations