This is an archived version of the documentation for SonarQube-7.3.
See the Latest Documentation for current functionality.

Code Viewer

The code viewer is the heart of SonarQube: it displays the source code of a file (both source and test files), and its high-level statistics:

  • Lines

  • Issues (generated by the rules activated on the quality profile)

  • Test coverage by unit or integration tests

  • Duplications within the same file or in other files

  • SCM information like who last committed a specific line and when

You will land on the code viewer:

  • when drilling down from the Measures and Code pages.

  • when reviewing issues on the Issues page.

  • when searching for a particular file using the search input at the top-right.

The code viewer has two aspects, the current file and pinned files.

Current File

Layout

The code viewer is composed of 2 parts:

  • The header lies across the top of the file. It displays useful information such as # lines, # issues, coverage and duplication percentages.

  • The source code is in the center, decorated with additional information such as SCM data, coverage and duplications bars.

Header

The header can contain up to four data blocks, one per main axis: Lines, Issues, Coverage (for source files) or Tests (for test files), and Duplications. Data blocks which aren't relevant to the current file won't be shown. For instance, if the project has no tests, the coverage number will be omitted. Similarly, the duplications block will be omitted if there are no duplications.

The source code

The main purpose of the code viewer is to show source code and any problems it may have. For that reason, issue, duplication, and test decorations are always visible, but issues may be collapsed if you don't come to the code viewer from the Issues page, and a yellow highlight is present on all new code.

The light yellow background is meaning: new code during the leak period.
The dark yellow background is meaning: new code during the leak period not covered by tests.

Additional actions

The actions menu at the top-right of the code viewer header offers additional options.

images/download/attachments/11641221/Selection_638.png

The most notable of these is "Show Details", which opens a modal popup with additional data on the file:

images/download/attachments/11641221/image2016-4-614_42_19.png

Pinned Files

Both source files and rule descriptions can be pinned directly:

images/download/attachments/11641221/image2016-4-614_37_14.png

or from another file's duplication detail.

You can adjust the height of the currently-active pinned window, minimize it, maximize it, and close it. The currently-active window will automatically be minimized if you change contexts or pin another file.

Further Reading

To learn more about the code viewer, please see :