Start FreeLog in
SonarCloud | Core concepts | Clean as You Code | About new code

About new code

On this page

New code is code that you've recently added or modified. To ensure you focus your efforts on the right lines of code, Sonar will highlight technical debt (issues, code coverage, etc) in the new code.

In pull requests, all code changes are considered new code. For branch and IDE, the new code definition setting tells Sonar which part of the code is considered new. 

Your new code definition

Each project in the Sonar solution has a new code definition. It’s a setting that determines what code in your projects is considered new code. 

Depending on the type of project you're working on, the best option to use will vary.  Here are a couple of use cases:

Use cases for new code definition option.

New code definition options

Previous version

Defines new code as any code that has changed since the most recent version increment of the project. 

Number of days

Defines new code as any code that has changed in the last X days.

Specific version

Defines new code as any code that has changed since a specific, defined version of the project. For more compliance with the Clean as You Code methodology, this option cannot be set in the UI, as it would require frequent user action to be kept up to date. 

Specific date 

Defines new code as any code that has changed since a specific, defined date.

New code period

For all the above options, SonarCloud calculates a new code period with a start and end date. All the code that falls between the date of your last analysis and the start date is considered new code. Here is how the start date is calculated:

  • Previous version: Date when the project was first incremented to the version in question.
  • Number of days: Current date minus the specified number of days.
  • Specific version: Date at which the project was upgraded to the version in question.
  • Specific date: The specified date.

All lines of code in all files under analysis that have changed since the start date of the new code period are marked. In SonarCloud, these lines are displayed in yellow.

Focus on new code in the UI

In the Sonar solution, all views that display found issues or other code metrics always prioritize the status of new code. Data on overall code is available but is not displayed by default. This encourages you to maintain focus on the new code.

The set of new code issues, in turn, affects many aspects of your results:

  • The default quality gate applies conditions only to new code issues.
  • In SonarQube and Sonarcloud: 
    • There are separate tabs for new code data vs. overall code data. 
    • Selecting the Issues in new code filter found on your project > Issues allows you to quickly switch between issues in new code or issues in overall code.
    • The activity graphs separate activity in the new code from activity in the overall code.

Next steps

In SonarQube, the new code definition can be set at the organization or project level.

To learn how to configure these options, see "Setting a new code definition" in the Setting up Clean as You Code section.


Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License