SonarQube Version: 6.7
Sonar Scanner: 3.0.3.778-windows
Plugin: sonar-javascript-plugin-5.1.1.7506
Problem Statement: Possibility of extending existing rules
Problem Details: In our code base we define a common function in the JS Controller file where it will have multiple function definitions inside the same. The cognitive complexity rule calculates the complexity from the top level and reports the number. We would like the cognitive complexity rule to ignore the first level function and then evaluate the inside functions.
Below is the sample code snippet for quick reference:
define([‘AbeServices’],
function (MainFunction) {
abc.register.controller(’$stateParams’, ‘$modal’, ‘_’, ‘$state’, ‘$scope’) {
_fun1 = function () {
.....
};
fun2 = function () {
.....
};
}
}
The expectation is in the above code, MainFunction cognitive complexity rule should ignore the same and nested functions (fun1, fun2) should be calculated.
The options considered from my end:
- Write the custom rule: It require to rewrite the cognitive complexity logic as well, is there a way i can extend the mentioned rule and write a custom rule to ignore the needful?
- Ignore Issues in Blocks: This will completely ignore the MainFunction along with nested functions.
- Resolve the issue as false positive, the number of false positive will grow as the code base grows and also every new file create will report one issue
Can someone guide what would be the better approach to address the same.
Thanks in advance.
Venkat Thota