You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SonarQube扫描lcov.info异常:TypeScript UI项目覆盖率问题求助

Alright, let's tackle this problem head-on. The core issue here is that SonarQube's TypeScript plugin automatically maps coverage data from compiled .js files back to their source .ts files—something you don't want, since you want Sonar to strictly follow what's in your lcov.info report. Here's how to fix it:

1. Disable Automatic Coverage Mapping Between TS and JS

First, turn off the plugin's default behavior that links JS coverage to TS source files. Add this to your Sonar configuration:

sonar.typescript.excludeCoverageFromAutoscan=true

This tells Sonar to stop inferring TS coverage from JS files and instead use the exact paths listed in your lcov.info.

2. Fine-Tune Source File and Coverage Scopes

Next, adjust your configuration to avoid duplicate scanning and ensure Sonar respects your coverage report:

# Include only your TypeScript source files as project code
sonar.inclusions=**/*.ts
# Exclude compiled JS files from being scanned as source code (prevents duplicate errors)
sonar.exclusions=**/*.js
# Don't exclude any files from coverage analysis (so Sonar can read the JS paths in lcov.info)
sonar.coverage.exclusions=
# Explicitly point to your coverage report
sonar.javascript.lcov.reportPaths=test-coverage/lcov.info

This setup ensures:

  • Sonar only analyzes your .ts source files for code quality
  • It doesn't treat compiled .js files as duplicate source code
  • It uses the exact coverage data from lcov.info without mapping it back to TS files

3. Verify Your Setup

After applying these changes:

  • Double-check that the file paths in lcov.info are relative to your project root (Sonar needs this to match files correctly)
  • Run your Sonar scan again, then check the coverage tab in SonarQube—you should see coverage only for the .js files listed in your report, with no unexpected TS coverage or duplicate scanning errors

Why Your Previous Configurations Failed

  • Using sonar.inclusions=**/*.ts alone: Sonar would still map JS coverage to TS files via the default plugin behavior
  • Setting sonar.coverage.exclusions=**/*.ts: This excluded TS files from coverage, but left JS files as source code, leading to duplicate scanning of TS and JS
  • Using sonar.language=ts: This restricted Sonar to only analyze TS files, which meant it ignored the JS coverage data in lcov.info

内容的提问来源于stack exchange,提问作者pkaramol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:56:57