Defining New Code
On this page
Defining what is considered new code is an important part of SonarQube's Clean as You Code approach to code quality and safety. By focusing on code that's been added or changed since your new code definition, you can set consistent quality requirements and expectations. Your new code will be issue-free and you'll clean up the code you encounter along the way. For more information on new code and why it's important, check out Clean as You Code.
Setting your New Code definition
You can define new code at the global, project, or branch level.
- Global level
You can set a global new code definition at Administration > Configuration > General Settings > New Code. What you define as new code at the global level will be the default for your projects. - Project level
You can set a new code definition for your project at Project Settings > New Code. What you define as new code at the project level will be the default for the project's branches if you're using an edition that supports multiple branches (starting in Developer Edition). - Branch level
You can define New Code for each branch from the Actions column of the branches table on the project's New Code settings page if you're using an edition that supports multiple branches (starting in Developer Edition).
New code definitions
You can define new code as changes from a previous version, a specific analysis, a reference branch, or within a specific period (number of days):
- Previous Version – Define new code as any changes made in your project's current version. This works well for projects with regular versions or releases. Available at the global, project, and branch level.
- Specific analysis – Choose a previous analysis as your new code definition. Any changes made since that analysis are considered new code. Available at the branch level starting in Developer Edition and the project level for community edition.
For Community Edition, past analysis is available at the project-level because Community Edition doesn't support multiple branches. Starting in Developer Edition, you can do this at the branch level, and each branch can be set to one of the branch's specific past analyses.
- Reference Branch – Choose a specific branch to define your new code. Any changes made from your reference branch are considered new code. Available at the project and branch level. You can also specify a reference branch using a scanner parameter, overriding the server's definition. See the Scanner Analysis Parameters.
- Number of days – Specify a number of days for a floating new code period. For example, setting Number of Days to 30 creates a floating new code period beginning 30 days from the current date. Available at the global, project, and branch level.
Was this page helpful?