Import statement is covered in sonar report for angular files

Hi,

Need help in resolving the import statement coverage in sonar for angular files.

Below is the sonar-project.properties files -

sonar.projectKey=com.myproject
sonar.projectName=MyProject
sonar.projectVersion=1.0

sonar.sourceEncoding=UTF-8

sonar.host.url=http://localhost:9000/
sonar.login=***
sonar.analysis.mode=publish
sonar.issuesReport.console.enable=true
sonar.sources=src
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.exclusions=**/*.spec.ts,**/*.stub.ts,**/coverage/**
sonar.java.binaries=**/target/classes
sonar.java.libraries=**/target/*.jar
sonar.coverage.exclusions=few-regEx-to-exclude-targetted-files

below are the version details for -
SonarQube: 7.9
sonar-scanner: 3.1.0
node: 14.15.0
karma-coverage: 2.0.3
Angular: 12
typescript 4.2.4 (added as dev dependency)

below is the output of sonar-scanner:

INFO: Scanner configuration file: /home/build/proj/node_modules/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/build/proj/sonar-project.properties
INFO: SonarQube Scanner 3.1.0.1141
INFO: Java 1.8.0_292 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-159-generic amd64
INFO: User cache: /home/build/.sonar/cache
INFO: SonarQube server 7.9.6
INFO: Default locale: "en_US", source code encoding: "UTF-8"
WARN: SonarScanner will require Java 11 to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=132ms
INFO: Server id: idoftheserver
INFO: User cache: /home/build/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=65ms
INFO: Load/download plugins (done) | time=2079ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=19ms
INFO: Project key: com.myproject
INFO: Base dir: /home/build/proj
INFO: Working dir: /home/build/proj/.scannerwork
INFO: Load project settings for component key: com.myproject
INFO: Load project settings for component key: com.myproject (done) | time=35ms
INFO: Load project branches
INFO: Load project branches (done) | time=48ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=20ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=68ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=1014ms
INFO: Branch name: master, type: long living
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/*.spec.ts, **/*.stub.ts, **/coverage/**
INFO:   Excluded sources for coverage: few-regEx-to-exclude-targetted-files
INFO: Load project repositories
INFO: Load project repositories (done) | time=109ms
INFO: 2220 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for css: Sonar way
INFO: Quality profile for java: project way
INFO: Quality profile for js: Sonar way
INFO: Quality profile for ts: Sonar way
INFO: Quality profile for web: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: ------------- Run sensors on module project
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=35ms
**** Java files analysis ***

INFO: Sensor SonarTS [typescript]
INFO: Analyzing 755 typescript file(s) with the following configuration file /home/build/proj/tsconfig.json
INFO: 755 files analyzed out of 755
INFO: Sensor SonarTS [typescript] (done) | time=59374ms
INFO: Sensor SonarTS Coverage [typescript]
INFO: Analysing [/home/build/proj/projects/global/coverage/lcov.info, /home/build/proj/projects/shared/coverage/lcov.info, /home/build/proj/projects/dashboard/coverage/lcov.info, /home/build/proj/coverage/lcov.info]
WARN: Could not resolve 127 file paths in [/home/build/vam-ui/projects/global/coverage/lcov.info, /home/build/vam-ui/projects/shared/coverage/lcov.info, /home/build/vam-ui/projects/dashboard/coverage/lcov.info, /home/build/vam-ui/coverage/lcov.info], first unresolved path: projects/global/src/test.ts
WARN: Found 152 inconsistencies in coverage report. Re-run analyse in debug mode to see details.
INFO: Sensor SonarTS Coverage [typescript] (done) | time=244ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=12ms

INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: Sensor Java CPD Block Indexer
INFO: Sensor Java CPD Block Indexer (done) | time=227ms
INFO: 218 files had no CPD blocks
INFO: Calculating CPD for 1219 files
INFO: CPD calculation finished
INFO: Analysis report generated in 365ms, dir size=10 MB
INFO: Analysis report compressed in 2919ms, zip size=4 MB
INFO: Analysis report uploaded in 1087ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://sonarqube01.url
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://sonarqube01.url
INFO: Analysis total time: 2:19.253 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 2:23.781s
INFO: Final Memory: 49M/1094M
INFO: ------------------------------------------------------------------------

tsconfig.json

{
  "compileOnSave": false,
  "allowJs":true,
  "compilerOptions": {
    "downlevelIteration": true,
    "outDir": "./dist/out-tsc",
    "baseUrl": ".",
    "paths": {
....
    },
    "sourceMap": true,
    "declaration": false,
    "module": "es2020",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "d3", "d3-dsv", "jasmine", "jasminewd2", "lodash", "node"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "strictInjectionParameters": true,
    "fullTemplateTypeCheck": false,
    "preserveWhitespaces": false
  }
}

Any help is greatly appreciated.

Hi,

First, your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

7.9.* → 8.9.2 → 9.1 (last step optional)

You may find the Upgrade Guide and the LTS-to-LTS Upgrade Notes helpful. If you have questions about upgrading, feel free to open a new thread for that here.

Regarding your actual question, SonarQube doesn’t calculate coverage, it merely reflects the contents of your coverage reports. So this is really a question for the maintainers of your coverage engine.

 
:woman_shrugging:
Ann