Sonar code duplication metrics
Sonar uses the following four metrics to cover code duplication. Duplicated lines can also be expressed as a percentage value and we will create an alert with a threshold value of five percent.
Name |
Description | |
---|---|---|
Duplicated Lines |
Number of physical lines touched by duplication. | |
Duplicated Blocks |
Number of duplicated blocks participating in duplication. | |
Duplicated Files |
Number of files containing duplicated lines or blocks. | |
Density of Duplicated Lines |
|
Creating Duplicated Code Alert
Log in to Sonar and navigate to the custom packt profile configuration screen. Add a new alert as shown in the following screenshot:
With the previous configuration, when duplication levels reach 10% or higher, an alert at level error will be triggered. If duplication is higher than 5%, the alert will be shown as a warning.