Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is SonarQube?

Learn what SonarQube does, what problems it finds in source code, and where it fits in a team workflow, with a runnable mini analyzer that shows the idea.

SonarQube is a platform that reads your source code, without running it, and tells you where the code is likely wrong, risky or hard to maintain. It checks thousands of rules across many languages, stores the results in a database, and shows them on a web dashboard. A quality gate then turns those results into a simple pass or fail that your pipeline can act on.

Teams use it because reviewers get tired. A person reading a pull request will spot a design problem but may miss a forgotten null check on line 212. A tool never gets tired, and it checks every change the same way. In this lesson you will see what SonarQube is made of, what kinds of findings it produces, and how it fits into daily work.

SonarQube itself cannot run on this site: it is a server with a database and a search engine. The code examples in this track are small, clearly labelled stand-ins written in Python. They show the same ideas (rules, issues, ratings, gates) so you can experiment. Menu names and commands are described from the real product; always check the documentation for your version, because names change between releases.

The big picture

Three things work together:

  1. A scanner runs on your machine or in CI. It reads the source files, runs the analyzers and sends a report to the server.
  2. The SonarQube server processes the report, compares it with the previous analysis, stores issues and measures, and evaluates the quality gate.
  3. You, through the web interface, an IDE plugin or a pull-request comment, read the findings and fix them.
flowchart LR
  A["Developer pushes code"] --> B["CI runs the scanner"]
  B --> C["SonarQube server<br/>(analysis + storage)"]
  C --> D["Quality gate: pass or fail"]
  D --> E["Dashboard, PR comment, IDE"]

The basic loop: push, scan, evaluate, show.

What it finds

SonarQube reports issues. Each issue points at a file and line, names the rule that fired, and explains why it matters and how to fix it. Issues fall into broad groups:

  • Reliability problems (bugs): code that is likely to crash or return a wrong result, such as using a possibly null value.
  • Security vulnerabilities: code an attacker could exploit, such as building SQL from user input.
  • Security hotspots: sensitive code that needs a human to decide if it is safe (see Security Hotspots).
  • Maintainability problems (code smells): code that works but is confusing, duplicated or needlessly complex.

Beyond issues, it measures things: lines of code, test coverage, duplication, complexity and an estimate of the time needed to fix everything (technical debt).

A stand-in analyzer

Real analyzers build a model of the code and apply rules to it. The stand-in below uses Python's ast module to do the same at toy scale. It looks for three problems: a mutable default argument, an unused local variable and a bare except.

Python A tiny rule-based analyzer (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice what the program does not do: it never runs load. It only walks the syntax tree. That is the defining feature of static analysis, which the next lesson explains further.

Counting what you found

A dashboard summarizes. This second stand-in groups issues by kind, the way the Overview page of a project does.

Python Summarize issues by kind (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The rule keys (for example python:S1481) are a real convention: a language prefix, then a rule number. The numbers in the sample data are only labels for the demo.

Where it fits in a team

A common setup looks like this:

  • Developers see findings in their IDE while typing.
  • Every pull request is scanned, and the quality gate result appears next to the tests.
  • The main branch is scanned after each merge, and a dashboard tracks trends.
  • A merge is blocked when the gate fails, so new problems are never added silently.

This approach is called Clean as You Code: you do not have to fix ten years of old problems first. You keep the code you touch clean, and the overall quality rises over time. You will meet it again in New Code and Clean as You Code.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does SonarQube analyze?

    SonarQube performs static analysis: it reads source files and applies rules, it does not run the program.
  2. 2. Which component sends the analysis report to the server?

    A scanner runs on your machine or in CI, analyzes the files and uploads a report to the server.
  3. 3. What is a quality gate?

    A quality gate is a set of conditions on measures; the project either passes or fails it.
  4. 4. Why does the stand-in analyzer in this lesson use the ast module?

    ast parses source into a syntax tree that rules can inspect, which is how static analysis works.

Summary

  • SonarQube is a server plus scanners that perform static analysis on source code.
  • It reports issues (bugs, vulnerabilities, code smells), hotspots and measures such as coverage and duplication.
  • A quality gate converts the results into a pass or fail decision.
  • Typical use: IDE feedback, pull-request checks and a main-branch dashboard.
  • The examples here are Python stand-ins; the real product is a server you install.

Next: Static Analysis Explained