Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube: Ignore files during coverage report

I want to provide a coverage report for a ui project.

The project mainly consists of .ts files which under version control.

The gulp command used to check coverage, generates .js files which are then checked for coverage. (and a coverage report that ... reports only on those files)

The .js files are not under version control and, when produced are intermingled with the .ts files (i.e., wherever there is a .ts file, a .js file will be generated next to it).

This creates the following issue:

When sonarqube generates coverage report, to my report above (pointed to by sonar.javascript.lcov.reportPaths), the .ts files are added (which of course have 0.0% coverage) and this breaks the actual cov value.

Is there a way / pattern to instruct sonarqube to:

a) perform code analysis on .ts files

b) ignore all .ts files when generating coverage report?

like image 982
pkaramol Avatar asked Jan 22 '18 09:01

pkaramol


People also ask

How do you exclude files from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class.

How do I exclude files in Sonarcloud?

Exclusions and inclusions can be set either in the UI or by key. In the UI the settings are under: Your Organization > Your Project > Administration > General Settings > Analysis Scope > Files.

How do I ignore issues in SonarQube?

You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Administration > General Settings > Analysis Scope > Issues. Note that the properties below can only be set through the web interface because they are multi-valued.

How do I set Sonar exclusions?

In Java, we can exclude Sonar checks using the built-in @SuppressWarnings annotation. This works exactly the same way as suppressing compiler warnings. All we have to do is specify the rule identifier, in this case java:S106.


1 Answers

Just found out in the project's documentation.

Ignore Code Coverage

You can prevent some files from being taken into account for code coverage by unit tests.

To do so, go to Administration > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property

There is also the following directive that can be used in the sonar-project.properties file:

sonar.coverage.exclusions
like image 59
pkaramol Avatar answered Sep 18 '22 14:09

pkaramol