Peakiq Blog
Level Up Your React & React Native Code Quality with SonarQube A Deep Dive
Discover how to use SonarQube to analyze and improve React and React Native codebases. This deep dive covers JavaScript, TypeScript, security, technical debt, and best practices.
🧠 Why SonarQube in React & React Native Projects?
While linters like ESLint and formatters like Prettier are great, they only scratch the surface. SonarQube brings:
- ✅ Deep static analysis (beyond lint rules)
- 🔒 Security vulnerability detection
- 🧹 Code smell detection
- 📊 Visual dashboards showing test coverage, maintainability, and technical debt
It's not about replacing your current tools — it's about supercharging them.
🛠️ Setting Up SonarQube Locally on macOS
Let’s get practical — no fluff.
Step 1: Install and Launch SonarQube
brew install sonar
sonar start
Visit: http://localhost:9000
Login with: admin / admin
You now have a running SonarQube server on your machine.
Step 2: Install the Sonar Scanner
This is the CLI tool that connects your code to SonarQube:
brew install sonar-scanner
Step 3: Add the Configuration File
At the root of your React/React Native project, create:
touch sonar-project.properties
Add:
sonar.projectKey=my-awesome-app
sonar.projectName=My Awesome App
sonar.sources=src
sonar.exclusions=**/__tests__/**,**/*.test.js,**/*.spec.tsx
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.javascript.lcov.reportPaths=coverage/lcov.info
🚦 Run the Analysis
Build and test your app (especially if you use Jest):
npm run test -- --coverage
Then:
sonar-scanner
Boom — your dashboard will now light up with real-time code insights.
🤖 React Native Considerations
With modern React Native apps, we often deal with:
- Shared components between iOS and Android
- JS-only code (in
src/) - Native modules (which we can skip)
So tweak the config:
sonar.sources=src
sonar.exclusions=android/**,ios/**,**/*.test.tsx
Use TypeScript + strict mode (tsconfig.json) to boost type safety — Sonar will respect it.
🧪 Test Coverage Integration
Want Sonar to show you what you’re not testing?
- Use
jest --coverage - Output
lcov.info - Hook that path in
sonar-project.properties
You’ll get heatmaps of untested components, perfect for spotting weak points.
💡 Bonus: Combine with Git Hooks
Use tools like:
npm install husky lint-staged --save-dev
To automatically lint & format before every commit:
"lint-staged": {
"**/*.tsx": ["eslint --fix", "prettier --write"]
}
This way, your Sonar dashboard is always clean before merging code.
📈 CI/CD? Go Beyond GitHub Actions
If you’re using GitHub Actions, Bitrise, or even Fastlane for React Native, integrate like this:
- name: SonarQube Scan
run: |
sonar-scanner \
-Dsonar.projectKey=my-awesome-app \
-Dsonar.sources=src \
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
Store your token securely via SONAR_TOKEN.
🧘♂️ Final Thoughts: Clean Code Is Sustainable Code
Codebases grow fast. React projects sprawl. React Native multiplies platforms. Without active quality gates, you’re inviting chaos.
SonarQube doesn’t just point fingers — it creates a shared understanding of quality across your team.
And in 2025, that’s not just helpful — it’s essential.