Skip to content

[CHORE]: Achieve zero flagged SonarQube issuesΒ #212

@crivetimihai

Description

@crivetimihai

πŸ”§ Chore β€” Achieve SonarQube Quality Gate Compliance


🧭 Chore Summary

Drive the project's SonarQube quality-gate to 0 actionable issues while keeping all tests green.


🧱 Areas Affected

  • Pre-commit hooks / linters
  • Build system / Make targets (make sonarqube, make pre-commit)
  • GitHub Actions / CI pipeline
  • Runtime codebase (quality fixes, code smells, coverage improvements, etc.)

βš™οΈ Context / Rationale

SonarQube static analysis surfaces code quality issues, vulnerabilities, bugs, and code smells before they reach production. A clean quality gate lets us maintain high code standards and ensures new code meets our quality baseline.


πŸ“¦ Related Make Targets

Target Purpose
make sonarqube Run SonarQube scan via sonar-scanner (Quality Gate)
make pre-commit Execute all hooks locally
make lint Meta-target (black + isort + autoflake + pylint + type checks)
make test Unit / integration tests
make smoketest Minimal E2E sanity check

Bold targets are mandatory; CI must fail if any of them reports issues.


πŸ“‹ Acceptance Criteria

  • make sonarqube passes the configured Quality Gate (no New Code bugs/vulns/security-hotspots).
  • Code coverage meets the Quality Gate threshold (typically 80%+).
  • make pre-commit runs clean with no diffs.
  • make test and make smoketest pass.
  • GitHub Actions enforces SonarQube Quality Gate (e.g. Sonar qualitygate step).
  • Changelog entry under "Maintenance".

πŸ› οΈ Task List (suggested flow)

  1. Baseline scan

    make sonarqube   # (requires SONAR_TOKEN)
  2. SonarQube remediation priorities

    • Bugs - Fix immediately (can cause runtime errors)
    • Vulnerabilities - Security issues that need addressing
    • Security Hotspots - Review and mark as safe or fix
    • Code Smells - Refactor to improve maintainability
    • Coverage Gaps - Add missing unit tests
  3. Common SonarQube fixes

    Issue Type Fix Strategy
    Cognitive Complexity Break down complex functions, extract methods
    Duplicated Code Extract common functionality into shared utilities
    Uncovered Lines Add unit tests for untested code paths
    Security Hotspots Review and either fix or mark as safe with justification
    Code Smells Follow suggested refactoring patterns
  4. Coverage improvement

    • Focus on critical business logic first
    • Add edge case tests
    • Test error handling paths
    • Use coverage reports to identify gaps
  5. Suppressions (last resort)

    • In Sonar, mark false positives as Won't Fix with a clear reason
    • Use inline comments sparingly: # NOSONAR with justification
    • Document any architectural decisions that lead to suppressions
  6. CI integration

    • Extend GitHub Actions to run SonarQube analysis
    • Configure Quality Gate to fail the build if not met
    • Set up branch analysis for PRs
  7. Local & container smoke-tests (unchanged but reiterated)

    • make venv install install-dev test smoketest – full local pass.

    • Docker: make docker-prod docker-run-ssl-host – build prod image & run containerised smoke-tests.

    • Compose: make compose-up (Postgres + Redis) with freshly-built :latest image.

    • DB migrations: run full Alembic cycle.

    • Helm / minikube:

      make minikube-install minikube-start
      helm upgrade --install mcp charts/mcp-stack
    • PyPI dry-run:

      make devpi-install devpi-init devpi-start
      make devpi-upload
      make clean
  8. Final validation

    make lint test smoketest sonarqube

πŸ“– References


🧩 Additional Notes

  • SonarQube's Quality Gate thresholds are configurable; work with your team to set appropriate levels.
  • Keep fixes granular (one issue type or module per commit) to simplify review & blame.
  • Consider setting up SonarLint in your IDE for real-time feedback before commits.

Metadata

Metadata

Labels

MUSTP1: Non-negotiable, critical requirements without which the product is non-functional or unsafechoreLinting, formatting, dependency hygiene, or project maintenance chorescicdIssue with CI/CD process (GitHub Actions, scaffolding)devopsDevOps activities (containers, automation, deployment, makefiles, etc)readyValidated, ready-to-work-on itemssecurityImproves security

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions