This an an archived version of the documentation for SonarQube version 4.5 & 4.5.x LTS.
See https://docs.sonarqube.org/display/SONAR/Documentation for current functionality
The component viewer is the heart of SonarQube: it displays the source code of a file (both source and test files), and all relevant information about it:
- Overall file measures, like lines of code, complexity, number of methods, ...etc
- Issues (generated by the rules activated on the quality profile) and their related technical debt
- Duplicated blocks within the same file or in other files, from both within the project and in other projects (if cross-project duplication is activated).
- Lines and branches covered by unit or integration tests
- SCM information (if the SCM Activity Plugin is installed) 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 component viewer:
- when drilling down from project dashboards using hunting services.
- when reviewing issues on the Issues page or in the Issues Drilldown.
- when searching for a particular file using the search input at the top-right.
The component viewer is composed of 3 parts:
- The header lies across the top of the file. It displays useful information and offers decoration and filtering actions.
- The workspace sits along the left of the file, and is used to keep track of navigation between files.
- The source code is in the center, decorated with additional information based on the options chosen in the header.
The header can contain up to 5 tabs, one per main axis: Overall Measures, Technical Debt and Issues, Coverage (for source files) or Tests (for test files), Duplications, and SCM. Tabs which aren't relevant to the current file won't be shown. For instance, if the project has no tests, the coverage tab will be omitted. Similarly, the duplications tab will be omitted if there are no duplications, and the SCM tab will be missing if the relevant plugin is not installed.
You can click on each tab to show its detailed metrics in a row below the tabs. Click the same tab again to toggle display of the metrics row.
Each tab consists of two parts: a thin blue line at the top, which controls decoration, and the tab itself, which controls filtering.
Expanding a tab does not activate a filter nor toggle decoration
Clicking on a tab does not have any impact on the source code that is displayed. It just shows detailed information about the code. You have to explicitly click on a filter or on a decoration bar to change something on the source code.
On top of each tab (except the first one), a light blue bar can be toggled to activate decoration of the source code with information relevant to the tab.
- The decoration action modifies which information is visible on the source code. For instance, you can click the thin blue bar at the top of the SCM tab to show the file's SCM annotations.
- Multiple decorators can be turned on at the same time.
- Once a decorator is activated (the light blue bar becomes darker) you may need to scroll down to find an instance of the relevant decoration. For instance, if you turn on the duplications decoration, the file you're looking at may not have a duplicated block at the top part of the file; you may need to scroll down to find one.
When a tab is expanded, it gives access to filtering actions:
- Filtering actions modify which part of the source code is visible.
- They can be toggled by clicking any metric in the tab that has ">" next to it. For instance, in the issues & technical debt tab, you can click on info > to show only code with info-level issues (and a few lines of context around those issues.)
Only one filter can be applied at a time across all the tabs
This means that if you activated the "Unresolved issues" filter in the Issues tab and you expand the Coverage tab, nothing will change in the source code until you select one of the filters of the Coverage tab.
Decoration and filtering work independently of each other. For instance, it's possible to filter the source code to see only the parts where there are info issues, while keeping the coverage information displayed on those lines - like in the example below:
If you click on one of the filters available on the Issue, Coverage, or Duplication tabs, the component viewer automatically toggles the appropriate decoration for you if it's not already active.
The workspace keeps track of your navigation history when you use the features of the component viewer itself to navigate between files. It can help you:
- remember which files you've just visited
- quickly move back to one of them
Note that the workspace is automatically cleaned up once you stop navigating through these 2 features.
The source code
The main purpose of the component viewer is to show source code:
Highlight of usage and declaration of variables and methods is available for Java only
This feature is available for Java code only for the moment, and limited to the scope of the file. It allows you to answer the questions:
- Where is this variable or method declared?
- Where is it used?
Eventually, this feature should be available for other languages and for identifiers declared outside the current file.
To learn more about the decorating and filtering capabilities of each of the header tabs, please see
- Overall Measures tab
- Technical Debt and Issues tab
- Coverage tab
- Tests tab
- Duplications tab
- SCM Information tab