The CodeScan New Code tab is a great way to keep track of new issues in your project.
How the New Code is set determines what issues are displayed as new issues. There are several options for this. The New Code can be configured for the specific project by navigating to the Project Settings > New Code menu from the project dashboard.
The New Code settings can be configured for the project or each branch by clicking on the settings wheel () at the bottom of this page.
By entering a date in the format yyyy-mm-dd, SonarQube™ will show the issues that have arisen since that date.
Number of days
SonarQube™ can be set to show the issues that have arisen within a certain number of days by entering the desired number. Remember that the issues found in the last 5 days will not be the same as a week from now.
By using the previous_version setting, the New Code will be tracked from the previous version set with the sonar.projectVersion parameter or from the Activity page.
For example, a scan is run on a project with the sonar.projectVersion 1.0 . After time, the project’s sonar.projectVersion is set to 1.1. The New Code Period set to previous_version would display all issues that have arisen since sonar.projectVersion 1.0.
The reference branch option compares all issues in the current branch to those in the specified reference branch. The New Code Tab will display the delta of those issues.
For example, the main branch of your project is pointing to a production environment. A second branch in your project is pointing at a developer environment. By defining the main branch as the reference for the second branch, you will be able to track new issues created in that developer environment.
By entering sonar.projectVersion into your projects, the New Code Period will display any issues that have arisen since that specific version.
For example, a scan is run on a project with the sonar.projectVersion BASELINE. The project’s sonar.projectVersion is then set to DEVELOPMENT and all necessary scans are run over time. The New Code Period set to BASELINE would display all issues that have arisen since the original scan.
It is important to note that all violations, including when they were introduced and the version in which they were introduced, are tracked. The New Code Period only filters this information on the project’s Overview dashboard and the Issues screen.
Problems can arise when users baseline projects with an entire code base and use the same project key to compare branches of code. It will count the files added as new files if the branch does not contain your full code base and you add files to your branch that were present in the initial baseline scan. This means all the violations in those files will register as new violations.
There are two options to avoid this:
- Make sure your entire codebase is present in the branch, not just the files you are working on.
- Baseline your project with the full code base before every scan.
Only One Version
If only one version is present in your project and the New Code Period is set to its default (previous version), it may not display properly. To display the New Code Period correctly, set the versions of your project scans with sonar.projectVersion or set the New Code Period to a specific date or number of days as mentioned above.
Click here to explore more on SonarQube™, SonarQube™: Clean As You Code