Exclusions in .sonarcloud.properties

Language: JavaScript

URL: GitHub - transformation-dev/blueprint

Question:
In .sonarcloud.properties I have the following, but I continue to get code smell alerts on test files including copy duplication code smell.

One guess about why is that I need to have a wildcard to specify the directory. Maybe I need **/*.text.js? Another guess is that SonarCloud ignores this file. Another guess is that I don’t know how to specify more than one exclusion in sonar.exclusions. Is it a comma with no spaces. Where are the docs for .sonarcloud.properties that covers these details. The stuff I found had no examples for multiple exclusions or matching those files in any path.

# Path to sources
# sonar.sources=
sonar.exclusions=package-lock.json,*.test.js
# sonar.inclusions=

# Path to tests
# sonar.tests=
# sonar.test.exclusions=
# sonar.test.inclusions=

# Source encoding
# sonar.sourceEncoding=

# Exclusions for copy-paste detection
sonar.cpd.exclusions=*.test.js

# Python version (for python projects only)
# sonar.python.version=

Hey there.

Your glob patterns need to look a bit more like this:

sonar.exclusions=**/*.test.js

Or, better yet, have them identified as Test files.

sonar.tests.inclusions=**/*.test.js

1 Like

Thanks Colin!!!

Next question.

I just setup the GitHub Action so I can get code coverage info. sonar-project.properties seems to duplicate the settings in .sonarcloud.properties. I’m guessing that I only need the sonar-project.properties now. Is it safe to delete .sonarcloud.properties?

If you’re moving to CI-based analysis for code coverage, then .sonarcloud.properties will be ignored and you should be safe to transfer that configuration to a sonar-project.properties file.

1 Like

Again thanks. How are status checks returned in CI-based analysis? I’m hoping they are still asynchrnous like the automated response… If not, I’m hoping they run really fast. I’d hate for my GitHub Action workflow to hang for minutes while SonarCloud analyzes my project.

There are two parts of the analysis.

  1. Scanner-side, where the rules are actually executed against your code. This happens in your CI environment.
  2. SonarCloud-side, where the report generated by the scanner is processed and things like status checks are returned

The first part… has to happen, and will contribute to your build time. The second part happens asynchronously.

1 Like