Chapter 01Lesson 03~105 minutes

Static Analysis, Clean Code, Technical Debt, and Quality Governance: Configuration, Design Patterns, and Trade-Offs

Design a quality policy that teams can sustain: choose Clean-as-You-Code versus all-code pressure, advisory versus enforced gates, default versus customized standards, and risk-aware interpretation without creating metric games.

Policy designNew CodeQuality gatesQuality profilesTrade-offs

Learning objectives

  • Choose between all-code remediation pressure and Clean-as-You-Code based on repository history and delivery risk.
  • Distinguish advisory reporting from enforceable quality-gate policy and define a safe adoption path.
  • Use default quality profiles as a baseline while governing justified customization.
  • Compare Standard Experience and MQR Mode policy semantics before changing modes.
  • Design exception and threshold changes as reviewable governance events rather than hidden shortcuts.

1. Policy design starts from risk, not from the settings menu

The local evidence chain from Lesson 2 is deliberately small. A production program adds many teams, languages, repositories, release cadences, and inherited problems. The challenge is no longer “can SonarQube find an issue?” It is “which findings should block which change, under which standard, with what exception process, and can the team explain that decision six months later?”

Design principle: configuration is an implementation of policy. Write the policy decision first; then change the quality profile, New Code definition, or gate. Otherwise the UI becomes the undocumented source of truth.

2. All-code pressure versus Clean-as-You-Code

An all-code posture asks the current repository to satisfy broad conditions across inherited and new code. That can be appropriate for a small greenfield repository or a focused remediation program. In a mature legacy codebase, however, inherited findings may be so numerous that every change begins behind a red wall.

Clean-as-You-Code concentrates enforcement on the code being added or changed now. It does not claim the historical backlog is harmless; it prevents the backlog from growing while teams plan deliberate modernization.

Context Reasonable starting posture Risk to manage
New service Strict New Code gate and high-quality defaults; often little difference between new and overall code at first. Over-customizing before real signal exists.
Large legacy monolith Protect New Code first; inventory overall debt separately. Using New Code as an excuse to ignore high-risk legacy hotspots forever.
Dedicated remediation release Explicit overall-code targets may be added for the campaign. Confusing temporary program goals with universal merge policy.

3. New Code definitions are governance boundaries

Current Community Build documentation provides multiple New Code definition strategies, including previous version, number of days, specific analysis, and reference branch. These options answer different questions. A version boundary can fit release-oriented products; a rolling window can fit continuous delivery; a specific analysis can anchor a migration; a reference-branch comparison can align work against a known baseline where supported by the project workflow.

The critical control is consistency: write down why the definition matches the team’s development model and who may change it. A silent baseline reset can make problematic code disappear from “new” scope without any code remediation.

4. Advisory versus enforced gates

An advisory gate is reviewed but does not automatically block a delivery action. It is useful during initial calibration, onboarding, or when a repository has unstable analysis inputs. An enforced gate becomes a release/merge control in CI or provider workflows. Enforcement is stronger, but only if false failures are rare and evidence is reproducible.

Stage Use Exit criterion
Observe Run analysis and collect baseline evidence. Inputs and task outcomes are reproducible.
Advisory Publish gate failures and require team review. Conditions represent intended risk; exceptions are rare and explained.
Enforced CI/SCM blocks delivery on gate failure. Ownership, escalation, outage behavior, and rollback are defined.

5. Default versus customized quality standards

SonarSource supplies built-in Sonar way quality profiles. They provide a maintained baseline and are a strong default for a new program. Customization can be justified for domain-specific coding standards, language/framework constraints, or organization policy, but every deviation creates maintenance responsibility.

Do not activate every available rule because “more checks must be safer.” Rules can overlap, conflict with local conventions, require context the project does not have, or create review volume that hides higher-risk findings. Start from a coherent default, observe false-positive/noise patterns, and make narrow reviewed changes.

Profile change record

profile · language · rule change · rationale · owner · date · affected projects · expected impact · rollback · review date.

6. Risk, severity, impact, and raw counts answer different questions

Raw issue totals are inventory. Severity/impact helps prioritize. The affected software quality tells you whether the concern is reliability, security, or maintainability in the active mode. Business context tells you whether a particular finding is urgent for this system. Good governance combines these layers instead of pretending one number is universally meaningful.

For example, ten low-impact maintainability findings in generated glue code may deserve less release attention than one credible high-impact security issue in an authentication path. Conversely, a long maintainability trend can still signal systemic delivery risk even if no single finding is severe.

7. Mode changes are migrations, not cosmetic preferences

Standard Experience and MQR Mode use different classification models. Because policy conditions and dashboards can depend on those classifications, changing mode should be treated like a governance migration: inventory automation and reporting assumptions, model expected issue/gate changes, communicate the vocabulary change, perform a controlled switch, and keep rollback/review evidence.

Do not compare “before” and “after” issue category totals across a mode change as if the measurement system were unchanged.

8. Keep edition/product boundaries explicit

This chapter’s policy concepts are taught through Community Build. Commercial SonarQube Server editions, Data Center Edition, and SonarQube Cloud can add capabilities or operational models that are outside this mandatory path. Likewise, server-side policy is different from CI-provider configuration and from IDE feedback. A design document should name which product owns each control rather than assuming every screenshot exists in every edition.

9. Exceptions must expire or they become hidden policy

Sometimes a team cannot remediate immediately: a third-party generated file may be noisy, a rule may not fit a framework, or a release may have an accepted temporary risk. The wrong solution is a silent suppression or permanent gate weakening. Create a narrow exception with owner, scope, rationale, compensating control, approval, and expiry/review date.

If many projects need the same exception, that is evidence that the standard itself deserves review. Governance should make this visible rather than forcing every team to invent a workaround.

10. Worked decision table

Scenario Recommended policy Evidence before enforcement
Greenfield internal API Sonar way baseline; strict New Code gate; advisory for first few runs, then enforce. stable revision mapping, low-noise findings, repeatable task/gate status.
15-year monolith Clean-as-You-Code; separately track overall remediation roadmap. chosen New Code definition, legacy inventory, exception ownership.
Regulated authentication component Risk-focused security/reliability policy plus explicit human security review. rule/profile provenance, hotspot review ownership, audit retention.
Generated client library Separate generated/source scope deliberately; document exclusions rather than suppressing everything. generation provenance, source scope proof, reason for exclusion.

11. Design lab: turn three repositories into policy proposals

  1. Copy the scenarios above into POLICY_PROPOSALS.md.
  2. For each, choose New Code strategy, default/custom profile approach, advisory/enforced stage, gate ownership, and exception process.
  3. State the current product mode (Standard Experience or MQR) and identify any wording/automation that would break if the mode changed.
  4. List at least three observable facts required before enforcement: revision consistency, scanner/task reproducibility, profile identity, gate result, issue noise rate, ownership.
  5. Review each proposal for a metric-gaming incentive. Remove developer rankings, “green at any cost,” or threshold changes made solely to pass the current run.

Knowledge check

Why is Clean-as-You-Code often safer for a large legacy repository than immediately gating all inherited issues?

When is an advisory gate preferable to an enforced gate?

Why not activate every rule?

What must happen before changing Standard Experience to MQR Mode?

What makes an exception governable?

Next lesson

Diagnose the evidence chain instead of fixing the dashboard

Lesson 4 deliberately breaks source, scanner, task, policy, and interpretation assumptions and applies an evidence-first troubleshooting sequence.

Official references and version notes

Version and compatibility note

Version-sensitive statements were rechecked against current SonarSource primary documentation on 2026-09-07. The executable local path in this chapter pins SonarQube Community Build 26.9.0.129388 with official image sonarqube:26.9.0.129388-community. Where a standalone SonarScanner CLI is used, the lab records 8.1.0.6389 from SonarSource update-center metadata. Current scanner Java/JRE auto-provisioning behavior and exact bootstrap requirements must be rechecked at execution time. Commercial SonarQube Server/Data Center and SonarQube Cloud features are not required for this chapter.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.