Skip to content

💚 fix(sonar): exclude generated + cluster/namespaced mirror from duplication gate - #40

Merged
konih merged 2 commits into
mainfrom
fix/sonar-cpd-exclusions
Aug 3, 2026
Merged

💚 fix(sonar): exclude generated + cluster/namespaced mirror from duplication gate#40
konih merged 2 commits into
mainfrom
fix/sonar-cpd-exclusions

Conversation

@konih

@konih konih commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

SonarCloud Quality Gate is failing on a single condition — every other condition passes (reliability A, security A, maintainability A, hotspots 100% reviewed):

Condition Threshold Actual
new_duplicated_lines_density ≤ 3% 22.9%

That's 5,002 duplicated lines across 55 files (measured via the SonarCloud API), and it splits cleanly into two by-design classes:

  • ~77% (3,862 lines) — Upjet-generated zz_*.go (dominated by zz_generated.resolvers.go and zz_generated.deepcopy.go). Machine-generated boilerplate, not ours to edit. Already treated as generated by golangci-lint (generated: lax) and ignored by codecov.
  • ~23% (~1,140 lines) — the intentional cluster/namespaced/ mirror of hand-written observe controllers and API types (publicnetwork, backuplist). Dual-scope is a deliberate Crossplane-v2 architecture; the two trees are near-identical twins by construction.

Neither is fixable by refactoring. SonarCloud runs as GitHub-App Automatic Analysis with no config in the repo, so it never got the same generated-code treatment the other quality tools already have.

Fix

Add .sonarcloud.properties (the file Automatic Analysis actually reads — sonar-project.properties is silently ignored under Automatic Analysis):

sonar.exclusions=**/zz_*.go
sonar.cpd.exclusions=internal/controller/**/*.go,apis/**/*_types.go
  • sonar.exclusions drops generated code from all analysis (mirrors golangci generated: lax / codecov ignore:).
  • sonar.cpd.exclusions suppresses the copy-paste flag on the mirrored hand-written files only — they still get bug/security/reliability analysis.

The 3% threshold is not loosened, so genuine future duplication regressions still fail the gate.

Verification

SonarCloud Automatic Analysis re-runs on this PR; its check is the verification. Post-merge it re-runs on main and clears the project gate.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

konih added 2 commits August 3, 2026 17:10
…ication gate

The SonarCloud quality gate failed on the sole condition
new_duplicated_lines_density (~22.9% vs <=3%). ~77% of the flagged
duplication is Upjet-generated zz_*.go and ~23% is the intentional
cluster/ <-> namespaced/ mirror of hand-written controllers and API types.

Add .sonarcloud.properties (the file Automatic Analysis actually reads;
sonar-project.properties is ignored):
  - sonar.exclusions=**/zz_*.go  (generated code, matches golangci generated:lax)
  - sonar.cpd.exclusions for the mirrored controllers/types (CPD only; they
    keep bug/security/reliability analysis)

Clears the gate without loosening the 3% threshold, so genuine future
duplication regressions still fail.
@konih
konih force-pushed the fix/sonar-cpd-exclusions branch from 2d1ef18 to 20d713a Compare August 3, 2026 15:11
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@konih
konih merged commit 8b998e4 into main Aug 3, 2026
16 checks passed
@konih
konih deleted the fix/sonar-cpd-exclusions branch August 3, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant