The sonarqube for ide extension in vscode is calculating a different In cognitive complexity score compared to sonarqube server.
Specifically, sonarqube server is adding 1 to the cognitive complexity in the below typescript code
But this is not counted by the sonarqube for ide extension in vscode.
I am using connected mode, so the cognitive complexity number is the same between server and client.
I have verified by introducing a function with cognitive complexity of 15 and also added the above code. This is not picked up in vscode but is in sonarqube server. Adding other cognitive complexity triggers does correctly cause the issue to show in vscode.
The version of sonarqube for ide is 4.30.0.
Below is some sample code to test with assuming a cognitive complexity limit of 15
export const testingCC = () => {
//cc score of below block is 15
if (1 === Math.random()) {
//+1
if (1 === Math.random()) {
//+2
if (1 === Math.random()) {
//+3
if (1 === Math.random()) {
//+4
if (1 === Math.random()) {
//+5
console.log('testingCC');
}
}
}
}
}
//any issues below should push over 15 and raise issue
//correctly shows cc over 15 and raises issue
// if (1 === Math.random()) {
// console.log('testingCC');
// }
//correctly shows cc over 15 and raises issue
//const foo = 1 === Math.random() ? '' : '';
//?? is treated as +1 when reasigning a variable only in sonarqube and not sonarqube for ide.
let foo = undefined;
foo = Math.random() ?? 12;
console.log(foo);
//oddly ?? is not treated as +1 when assigning to a const
const bar = Math.random() ?? 12;
console.log(bar);
};