Showing Cognitive Complexity error for the below code without hint. Can somebody help me on this?
let titleSize: any = "h4",
descriptionSize: any = "body1";
if (mobileDevice) {
titleSize = "h5";
descriptionSize = "body2";
}
Showing Cognitive Complexity error for the below code without hint. Can somebody help me on this?
let titleSize: any = "h4",
descriptionSize: any = "body1";
if (mobileDevice) {
titleSize = "h5";
descriptionSize = "body2";
}
Hi,
Welcome to the community!
Could you show the entire code / issue?
And I guess you’re asking for hints on refactoring to reduce the Cognitive Complexity?
Ann
Thank you so much for the response Ann.
Please find the attached screenshot. I am struggling with the line number 183 to 198. I tried with normal if…else and ternary also, but getting the same error.
Hi,
Cognitive Complexity issues are raised when the overall complexity of a method/function is above the configured threshold, which is 15 by default.
Those secondary locations are showing you that lines 187, 191, and 195 contribute to the funciton’s cumulative complexity. And they don’t strike me as immediate candidates for refactoring. If you’d like to share the entire method, I’ll be happy to take a look and make recommendations for any possible refactoring I see.
Ann