Chapter 09Lesson 01~130 minutes

Rules, Rule Types, Severities, Quality Profiles, and Customization: Core Concepts and Mental Model

Treat rules and quality profiles as versioned executable analysis policy, not a list of toggles: identify rule provenance, effective profile assignment, inheritance, mode-specific classification, and the downstream issue/gate evidence.

RulesQuality profilesInheritanceMQR / StandardGovernance

Learning objectives

  • Explain rule definition → profile activation → analysis → issue population → gate evaluation.
  • Distinguish rule key/repository, activation, parameter override, project association and issue state.
  • Use MQR and Standard Experience classification language correctly.
  • Explain Sonar way, custom profiles, defaults and inheritance.
  • Perform read-only rule/profile inspection before mutation.

1. The policy problem

Chapter 08 proved what files enter analysis. Chapter 09 controls what questions Sonar asks of those files. Installed analyzers contribute rule repositories; quality profiles choose and configure the active rules for each language; project association selects the profile; analysis creates issues; the Quality Gate evaluates the resulting state. A change in any of those policy inputs can change issue counts even when the source revision is identical.

Governance invariant: never deactivate a rule or lower downstream policy simply to make a dashboard green. Every activation, deactivation, parameter/severity override, default-profile change and exception needs a technical rationale, owner, blast-radius estimate, evidence and rollback.

2. Mental model: rule repository to release evidence

Rule availability, policy activation and downstream result are separate
flowchart TD
A[Analyzer / rule repository] --> R[Rule key + status + defaults]
R --> P[Language quality profile]
SW[Sonar way / parent] --> P
P --> E[Active rules + overrides]
Q[Default or project association] --> E
F[Indexed files from Chapter 08] --> N[Analysis]
E --> N
N --> I[Issues / measures]
I --> G[Quality Gate]
H[Profile + analyzer history] --> V[Governance evidence]
I --> V
G --> V

A rule key such as python:S3776 identifies one check in an analyzer repository. A quality profile is language-specific and selects active rules. A project association chooses a non-default profile for a project. An issue is a result of violating an active rule. A Quality Gate is downstream policy; it does not decide which rules execute.

3. Do not blend these states

State Owner Examples Evidence
Rule definition Analyzer/repository key, title, Ready/Beta/Deprecated, default classification, configurable parameters Rules page + analyzer/server version
Activation Quality profile active/inactive in Python profile profile active-rule list
Override Custom profile threshold or severity/impact different from parent Inheritance/overridden marker + profile backup
Assignment Instance/project policy language default or explicit project association Quality Profiles + Project Settings
Analysis Scanner + Compute Engine report upload, CE task, issues/measures scanner log, report-task.txt, CE task
Gate Quality Gate pass/fail gate status separately from scanner/CE
Governance Team/process owner, rationale, review date, rollback change record and before/after evidence

4. MQR Mode versus Standard Experience

Current Community Build supports two instance modes. New installations use MQR Mode by default. MQR can assign a rule impacts on security, reliability and/or maintainability, with severities Blocker, High, Medium, Low, Info. Standard Experience retains Bug, Vulnerability, Code Smell, Security Hotspot rule types with Blocker, Critical, Major, Minor, Info severity.

Do not translate the two vocabularies mechanically, and do not treat severity as exploitability, CVSS, business loss or developer performance. Security Hotspots are review targets whose vulnerability status is not known until review.

5. Sonar way and custom profiles

Sonar way is the built-in profile supplied for a language and cannot be edited. A language also has one default profile; projects without an explicit association use it. Custom profiles can be created by Extend, Copy, blank creation or import. SonarSource recommends extending Sonar way for most customization because the child inherits parent evolution such as newly implemented rules, configuration changes and deactivation of deprecated rules.

A child can add rules and can override configurable rule settings; inherited overrides can later be returned to parent policy with Revert to Parent Definition. A copied profile is independent and therefore demands its own update discipline.

6. Read-only inspection checklist

Inspect Question Record
Administration → Configuration → Mode Which classification model is active? MQR or Standard, timestamp
Rules → Python → S3776 What rule is installed? repository/key, status, current classification, configurable threshold
Quality Profiles → Python Which profile is built-in/default? Sonar way markers, active/deprecated counts
Project Settings → Quality Profiles Which profile does this project use? default vs explicit association
Background task / analysis history What result predates a profile change? revision, CE task, issue count, gate

7. Rule status and analyzer provenance

Rules can be Ready, Beta or Deprecated. Commercial analyzers and third-party plugins can also add rules. Therefore a rule inventory needs repository/analyzer provenance and version, not only a display title. After an upgrade, a profile with the same name can still represent changed policy because the underlying analyzer rules evolved.

8. DevOps connection: make policy reproducible

The minimum reconstructable chain is revision → indexed files → analyzer versions → effective quality profiles → active rules/overrides → scanner report → CE task → issue population → gate. That lets a reviewer tell whether a result changed because the source changed or because analysis policy changed.

Knowledge check

Can Sonar way be edited directly?

What does a quality profile control?

What severity names belong to MQR Mode?

Does the Quality Gate select active coding rules?

Why can same-revision issue counts change after an upgrade?

Next lesson

Run one controlled profile experiment

Lesson 2 extends Sonar way, changes one safe S3776 threshold in a disposable child profile, compares same-revision results, and proves rollback.

Official references and version notes

Version and compatibility note

Rechecked on 2026-09-07. Mandatory examples target private/local SonarQube Community Build 26.9.0.129388 and SonarScanner CLI 8.1.0.6389. Current Community Build baseline is 26.9.0.129388; current commercial SonarQube Server baseline is 2026 Release 4.1 with 2026.1.5 as the current 2026 LTA patch line. New Community Build instances use MQR Mode by default, but every lab records the actual mode and never switches it. MQR uses Blocker/High/Medium/Low/Info severities on software-quality impacts; Standard Experience uses Bug/Vulnerability/Code Smell/Security Hotspot types with Blocker/Critical/Major/Minor/Info severity. Sonar way is built-in and immutable. The hands-on experiment extends Python Sonar way and tunes python:S3776; verify installed rule metadata before changing it because analyzer behavior can evolve. No third-party plugin, commercial edition, CI provider, enterprise identity, SonarQube Cloud account, branch/PR analysis or production source is required.

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.