Excluding Files from SonarCloud Scan Using Dart Comments

Issue: Excluding Files from SonarCloud Scan Using Dart Comments

I need help ensuring that specific Dart files are excluded from SonarCloud scans using the // coverage:ignore-file comment. Currently, this approach works for my local coverage reports but is ignored by SonarCloud.

What I’ve Tried:

  • The // coverage:ignore-file comment successfully excludes files from local coverage reports.
  • My lcov.info report correctly reflects the expected exclusions.
  • I’m importing this filtered lcov.info into SonarCloud during CI, but the coverage percentage reported by SonarCloud is still different from my local report.

Constraints:

  • I can use SonarCloud’s exclusion parameters, but:
    • There are many files with non-standard naming, making it difficult to define an exclusion pattern.
    • Manually adding each file is tedious.

CI Setup:

  • CI System: GitHub Actions
  • SonarCloud Scanner Configuration:
    - name: Filter coverage report
      run: |
        lcov --extract coverage/lcov.info 'lib/app/controllers/**/*controller.dart' 'lib/app/features/**/*controller.dart' -o coverage/filtered_lcov.info
        genhtml coverage/filtered_lcov.info --output-directory coverage/html
    - name: SonarCloud Scan
      uses: sonarsource/sonarcloud-github-action@v3.1.0
      with:
        args: >
          -Dsonar.organization=${{ env.SONAR_ORGANIZATION }}
          -Dsonar.projectKey=${{ env.SONAR_PROJECT }}
          -Dsonar.qualitygate.wait=true
          -Dsonar.sources=.
          -Dsonar.inclusions=lib/app/controllers/**/*controller.dart,lib/app/features/**/*controller.dart
          -Dsonar.dart.lcov.reportPaths=coverage/filtered_lcov.info
          -Dsonar.c.file.suffixes=-
          -Dsonar.cpp.file.suffixes=-
          -Dsonar.objc.file.suffixes=-
          -Dsonar.branch.name=${{ github.ref_name }}
    

Question:

  • How can I ensure that SonarCloud respects // coverage:ignore-file?
  • If that’s not possible, what’s the best way to exclude files dynamically without manually listing each one?

Hi,

Welcome to the community!

You’ll need to configure those file exclusions on the SonarQube for Cloud side. As a general rule, we don’t honor in-file exclusions, although I will pass this on to the language experts for consideration.

 
HTH,
Ann