Executable lines
On this page
These are the guidelines that SonarSource uses internally when defining executable lines for a language. Community plugins are not required to adhere to these guidelines. They are provided here only in case they are useful.
Things that are executable
Executable lines data is used to calculate missing test coverage for files that are not included in coverage reports. Ideally, executable line counts will be at or just under what coverage engines would calculate.
Generally, each line containing a statement should count as an executable line, with the exception that compound statements ({}) are ignored, although their contents are not. So, for example:
Things that are ignored
!Statement: +0
Since some coverage engines mark these things as executable, it's worth stating explicitly that we will ignore them:
- the method signature of a method definition.
- the method signature of a method definition
Imports, Declarations: +0
Imports, package and namespace statements, declarations, and a few other things demonstrated below are ignored.
Location
The presence of executable code on a line makes the entire line executable. If a statement is split over multiple lines, the line to be marked executable is the first one with executable code. Given that, a for
loop is considered executable:
Regardless of the number of lines across which nested statements are spread, the executable line count should only be incremented by one, since typically the execution of one naturally follows from the other.
We ignore here the possibility that bar()
could throw an exception, preventing foo
from being executed.
Exceptions
Python
# pragma: no cover
exempts a block from coverage. For example:
JavaScript
We mark variable declarations as executable. For example:
Was this page helpful?