New code
New code in the context of Clean as You Code
Focusing on new code is an important step in getting the most out of SonarQube for Eclipse. When you run an analysis on your main branch (or other long-lived branches) in SonarQube (Server, Cloud) or SonarQube Community Build, SonarQube for Eclipse uses the New Code Definition (NCD) to determine which issues you should focus on fixing, and calls out that these issues are found in new code. Focusing on new code is at the core of implementing the Clean as You Code strategy, knowing that the other code will be incrementally fixed over time.
To achieve this, SonarQube for Eclipse offers the Focus on new code feature to highlight new code in the IDE.
Your new code definition
When SonarQube for Eclipse is running in Connected Mode, the SonarQube for Eclipse uses the NCD defined in SonarQube (Server, Cloud) or SonarQube Community Build. When SonarQube for Eclipse is running in standalone mode, a locally defined new code period highlights your new code.
Running SonarQube for Eclipse in connected mode offers more opportunities to choose how you define new code.
New code definition options
When you use the NCD found in the SonarQube Server, SonarQube Cloud, or SonarQube Community Build quality profile, you have more opportunities to choose how to define new code. Check out their respective pages for details.
Without Connected mode, new code is defined by a new code period: any code added or changed in the last 30 days is considered new code. The 30-day timeframe is defined using Git.
When not using Git, the new code period begins with the first SonarQube for Eclipse analysis.
There is no option to manually define a new code period in SonarQube for Eclipse.
Setting your focus on new code
The Focus on new code feature works when SonarQube for Eclipse is running in either connected mode or standalone mode. As mentioned above, new code is defined differently in each mode.
Setting your focus on new code has these prerequisites running in Connected Mode:
- Your local project must be bound to a project in SonarQube Server, SonarCloud, or SonarQube Community Build.
- The new code definition must be defined in SonarQube (Server, Cloud) or SonarQube Community Build using a Previous version, Number of days, or Specific analysis.
- The Reference branch new code definition is not supported. Please check the documentation in SonarQube Server, SonarQube Cloud, or SonarQube Community Build to properly set your new code definition.
Setting the focus on new code is easy. To show or hide issues found in your Overall code, go to Eclipse Window > Preferences > SonarQube (or Eclipse > Settings… > SonarQube for Mac OS) and select Show SonarQube markers only for New code.
When switching between modes, settings are applied globally to all projects open in your Eclipse workspace.
When deciding to override a globally defined new code definition at the project level in SonarQube (Server, Cloud) or SonarQube Community Build, note that it is not possible to specify a unique New Code Definition at the branch level and still activate the Show SonarQube markers only for New code option.
Running SonarQube for Eclipse in connected mode with SonarQube Server, SonarQube Cloud, SonarQube Community Build offers more opportunities to choose how you define new code. Check out their respective pages for details.
How the new code definition affects the analysis results
The core idea of Clean as You Code is that you focus your attention and effort on new code (code that has been added or modified recently) and improve your code incrementally. SonarQube Server and SonarQube Cloud use your NCD as a baseline for code comparison, to identify what is new code which reinforces the Clean as You Code strategy by only showing you issues found in new code.
- When running SonarQube for Eclipse in connected mode and enabling the Focus on new code feature, the NCD from SonarQube (Server, Cloud) is used to show you only issues found in new code.
- When running SonarQube for Eclipse while not in connected mode and enabling the Focus on new code feature, every SonarQube for Eclipse analysis will show you only issues found in new code.
The Focus on new code feature gives you immediate feedback in the IDE, before you submit new code with new issues.
Was this page helpful?