Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


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
  • All tests of a given test file, along with their execution time and their status

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 and offers decoration and filtering actions.
  • The source code is in the center, decorated with additional information based on the options chosen in the header.

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 its effort to fix it. 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 the marker for new code only appears when a differential has been applied:

Additional actions

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

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

Pinned Files

Both source files and rule descriptions can be pinned directly:

or from another file's duplication detail:

 

Similarly, test files can be pinned from coverage detail, and rule descriptions can be pinned from issue messages:

 

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 :