I am very new to sonarlint, So after installing it and analyzing the file, I have seen a number indications in my code. I searched on google about the same but didn’t find anything. A version of Sonnarlint that I am using is 7.4 on Spring Tool Suite 4 Version: 4.14.1.RELEASE, Build Id: 202204250734
Considering it has been installed 1M times, definitely, someone would come to this. So please guide me to understand this.
What you're seeing is the Complexity
metric of your code.
This is defined by Sonar as:
Complexity (complexity) It is the Cyclomatic Complexity calculated based on the number of paths through the code. Whenever the control flow of a function splits, the complexity counter gets incremented by one. Each function has a minimum complexity of 1. This calculation varies slightly by language because keywords and functionalities do.
With specific details for Java (your code looks like Java):
Keywords incrementing the complexity: if, for, while, case, catch, throw, &&, ||, ?
This means that every number you see in red is an additional path your code takes, increasing the total complexity of your code.
The general goal of Clean Code is to keep the complexity of your classes and functions low, in order to increase code readability, cohesion and to follow the single responsiblity principle.
The corresponding rule in Sonar is for example: https://rules.sonarsource.com/java/RSPEC-1541
The configuration of Sonar can be set to allow a maximum complexity number, and your goal would be to reduce the complexity of your code to meet that limit (where ever it makes sense).
References: