Engineering summary: Code Quality

Purpose

Code Quality summary shows metrics related to the quality of a written code such as a code complexity, maintainability, violations, duplicates, etc..  Metric values are aggregated for the items selected in Project settings/Code Quality management system (e.g. Sonar).

How metric helps

Code Quality summary helps to understand, assess and track code health and quality and take actions to improve a code writing process in the team.

How metric works

Chart overview

Chart provides several views:

1 Main view: shows aggregated values for the metrics (on the left) and the same for each project (table on the right):

2 Single view: it opens by click on an item in the table at Main view. Single view reveals metrics values for a selected project:

3 Drill down: it opens by click on a metric name at Single view (a hyperlink). Depending on a metric there opens a chart revealing a metric trend in time:

Calculation 

The chart is based on a Code Quality data source configuration; only selected projects are taken into account:

See also Sonar configuration.



Metrics included into Main view:

Metric

Calculation

Unit of Measure

Metric

Calculation

Unit of Measure

Total Projects

absolute number of selected projects

item

Technical Debt

the sum of tech debt for selected projects

hours

Vulnerabilities

absolute number of vulnerabilities (all types) in selected projects

item

Code Smells

absolute number of code smells in selected projects

item

Unit Test Coverage

Σ(UT1*LOC1 + UT2*LOC2 ...+UTn*LOCn)/ΣLOC1..n

where

UT - unit test coverage in a particular project

LOC - number of code lines in a particular project

Example:

Given:

  • project 1 with a number of code lines 100 and unit test coverage 70%

  • project 2: lines of code 300 and unit test coverage 60 %

Code Coverage = (100*0.7 + 300 * 06)/(100+300)*100% = 62.5 %

%

Duplicated Code

Σ(DL1*LOC1 + DL2*LOC2 ...+DLn*LOCn)/ΣLOC1..n

where

DL - number of duplicated lines in a particular project

LOC - number of code lines in a particular project

%

Maintainability Grade

∑Grade*LOC / ∑LOC,

where

- Grade is A..E per Sonar for a project:  

  • <=5% of the time that has already gone into the application, the rating is A

  • between 6 to 10% the rating is a B

  • between 11 to 20% the rating is a C

  • between 21 to 50% the rating is a D

  • anything over 50% is an E


- LOC is the size of a project code base

Rounding the result: down to the whole number and then take the grade from the above.

Example: 
Repo 1 of A grade for 20 LOC, Repo 2 with D grade for 300 LOC.
(100*20 + 25*300)/(20+300) = 20% ==> C grade

grade

Quality Gate* status: Passed

absolute number of projects meet quality gate measures

item

Quality Gate status: Failed

absolute number of projects do not meet quality gate measures

item

Lines of Codes

absolute number of code lines in selected projects

item

Files

absolute number of files in selected projects

item

Classes

absolute number of classes in selected projects

item

*See more about quality gates in Sonar.

Metrics included into single view:

Metric

Calculation

Unit of Measure

Metric

Calculation

Unit of Measure

Maintainability Grade

∑Grade*LOC / ∑LOC,

where
- Grade is A..E per Sonar for a project:  

  • <=5% of the time that has already gone into the application, the rating is A

  • between 6 to 10% the rating is a B

  • between 11 to 20% the rating is a C

  • between 21 to 50% the rating is a D

  • anything over 50% is an E


- LOC is the size of a project code base

Rounding the result: down to the whole number and then take the grade from the above.

Example: 
Repo 1 of A grade for 20 LOC, Repo 2 with D grade for 300 LOC.
(100*20 + 25*300)/(20+300) = 20% ==> C grade

grade

Technical Debt

sum of a tech debt for a selected project

hour

Duplicated Code

ΣDLN0*LOCN0 *100%

where

DL - number of duplicated lines for a selected project

LOC - number of code lines for a selected project

%

Code Smells

absolute number of code smells in a selected project

item

Blocker

absolute number of all Blocker issues for a selected project

item

Critical

absolute number of all Critical issues for a selected project

item

Major

absolute number of all Major issues for a selected project

item

Minor

absolute number of all Minor issues for a selected project

item

Vulnerability

absolute number of vulnerabilities (all types) in a selected project

item

Security Rating

overall grade of a security reliability of the project code base from "A" (the best) to "E" (the worst). 

grade

Unit Test Coverage

percentage of a source code covered by unit tests

%

Line of codes

total number of code lines for a selected project

item

Success

percentage of successful unit tests

%

Failure

number of failures in unit testes for a selected project

item

Error

number of errors in unit tests for a selected project

item

Test

number of tests in a selected project

item

By click on a hyperlink in single view the following charts open:

Hyperlink

Chart to show

Hyperlink

Chart to show

Maintainability Grade

Code Maintainability Rating

Technical Debt

Technical Debt 

Duplicated code

Duplicated Lines

Blocker issues

Blocker Violations

Vulnerability

OWASP Security Vulnerabilities

Security rating

Security Rating

Unit test coverage

Unit Test Coverage

Lines of code

Code Base Change Trend

Unit tests: Success

Unit Test Success Rate

Unit tests: Test

Unit Tests Count

Data Source

Data for the chart can be collected from Sonar.