File can't be indexed twice

When running the PR configured in Github Actions, the SonarCloud execution fails, I have tried several ways to solve the error, but I have not been able to achieve it

Repository: Github

CI: Github Actions

Scanner command:

sonar.organization=softcrumhq
sonar.projectKey=softcrumhq_softcrum-frontend-corporate

sonar.exclusions=src/assets/css/tailwind
sonar.sources=.

sonar.javascript.jstest.reportsPath=coverage
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=test-report.xml
sonar.test.inclusions=
sonar.test.exclusions=src/actions/*.js,src/components/*.js,src/config/*.js,src/language/*.js,src/stores/*.js,postcss.config.js,server.js,tailwind.config.js

sonar.tests=.
sonar.sourceEncoding=UTF-8

Languages of the repository: Create React App
https://sonarcloud.io/dashboard?id=softcrumhq_softcrum-frontend-corporate
File package.json can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test file

Welcome to the community!

That error message indicates the problem precisely: the source files and test files overlap, and this is not allowed. In your specific example, having sonar.sources=. and sonar.tests=. has the effect that all files are considered as both sources and tests by default, except the ones you listed in exclusions. And since package.json is not part of any exclusions, it cannot be decided if it’s a source or a test file.

Please read the Narrowing the focus page in our documentation, which explains in detail how to configure your sources and tests to avoid overlaps.

1 Like