This article describes the issue I faced when trying to configure pre-commit and CI pipeline for my tech blog site using SonarLint. Specifically, I encountered a problem where SonarLint's exclusion settings didn't work as expected.
Follows the standard Next.js layout:
app/
├── layout.tsx
├── page.tsx
├── global.css
└── …
node_modules/ <– auto-generated by npm
coverage/ <– generated by Jest
public/
Building a CI pipeline and pre-commit hook that runs the following:
prettier
checkeslint
sonarlint
(code analysis)jest
tests with coveragenpx prettier --check . &&
npm run lint &&
npx sonarlint --exclude 'node_modules/**,coverage/**' &&
npm test -- --coverage --ci --silent=false
The exclusion option in SonarLint doesn't work when multiple directories are specified using --exclude
:
node_modules/**
), it works fine.'node_modules/**,coverage/**'
) does not exclude them..sonarlintignore
file**/node_modules/**
)This appears to be a known SonarLint issue. There are several similar unresolved reports on the SonarSource community, indicating a possible bug.
So as a temporary workaround, I added the following command before running the analysis:
rm -rf coverage &&
This simply deletes the folder before SonarLint scans the project.
In my case, there were only two directories to exclude, and one (coverage) could be safely removed beforehand. However, this approach won't scale if I need to exclude more directories.
If you're facing the same issue, I recommend either: