In simple words
- Issue: one problem SonarQube found in the code.
- Bug / vulnerability / code smell: something that will break, something attackers could use, and something that makes code hard to maintain.
- Rating: a grade from A to E for reliability, security and maintainability.
- New code: code changed recently, such as since the last release. Gates focus on it.
- Project key: the unique ID of a project in SonarQube.
Big picture
SonarQube has two parts that work together, like a camera and a photo album.
- The scanner looks at your code and takes a "photo" (it sends a report).
- The server stores every photo, shows them on a web page, and decides pass or fail.
Your code -> Scanner (in your laptop or CI) -> report -> SonarQube server -> web page + gate resultThe words you will see
| Word | Plain meaning |
|---|---|
| Project | One code base that is analysed, such as shop-api |
| Project key | A short unique id for the project, like acme_shop-api |
| Analysis | One scan. Each analysis is saved with a date |
| Issue | One problem found in one place in the code |
| Rule | The check that produced an issue, such as "do not leave empty catch blocks" |
| Quality profile | The list of rules switched on for a language |
| Quality gate | The pass or fail conditions for a project |
| Metric | A number such as lines of code, coverage or duplication |
| Token | A secret key the scanner uses to log in |
Types of issue
| Type | Question it answers | Example |
|---|---|---|
| Bug | Will this break? | A null value is used without a check |
| Vulnerability | Can this be attacked? | A password is written in the code |
| Security hotspot | Is this sensitive code safe? A person must decide | Use of a weak hash |
| Code smell | Will this be hard to maintain? | A function with too many branches |
Newer versions also group issues by what they affect: Security, Reliability and Maintainability. The idea is the same.
Severity and ratings
Each issue has a severity such as Blocker, High, Medium or Low, so you fix the dangerous ones first.
The server also gives each area a grade from A (best) to E (worst): Reliability, Security and Maintainability. They are easy to read in a meeting.
New code and overall code
This is the most important idea in the course.
- Overall code: everything in the project, old and new.
- New code: only what changed recently (since a date, a version or the last release).
SonarQube lets you judge new code strictly while living with old problems for now. This approach is called Clean as You Code. Lesson 08 explains it fully.
Editions
| Edition | Good for |
|---|---|
| Community Build | Free. Single-branch analysis, many languages |
| Developer | Adds branch and merge request analysis, more security checks |
| Enterprise | Adds portfolios, reports and extra languages |
| Data Center | High availability for very large setups |
Features move between editions over time, so check the current comparison on the SonarQube website before you plan.
The grades in plain words
| Grade | Reliability and Security | Maintainability |
|---|---|---|
| A | No bugs (or vulnerabilities) | Debt is 5% or less of the time it took to write the code |
| B | At least one low-impact problem | Debt 6% to 10% |
| C | At least one medium-impact problem | Debt 11% to 20% |
| D | At least one high-impact problem | Debt 21% to 50% |
| E | At least one blocker | Debt over 50% |
The exact wording of severities changes between versions. The idea stays the same: one serious problem is enough to lower the grade.
One analysis, start to end
Follow one scan to see how the words fit together:
- You run the scanner and give it the project key and a token.
- The scanner reads the code and sends a report to the server.
- The server runs the rules from the project's quality profile.
- Each problem found becomes an issue, saved with this analysis and its date.
- The server works out the metrics (coverage, duplication, grades).
- The quality gate looks at the new-code metrics and says Passed or Failed.
Good and bad project keys
| Key | Verdict |
|---|---|
acme_shop-api | Good: company, then service |
shop-api | Risky: another team may use the same name |
My Project! | Bad: spaces and symbols are not allowed |
Common mistakes
- Mixing up a bug and a code smell. A bug is wrong behaviour; a smell is hard-to-read code.
- Looking only at overall numbers on an old project and feeling hopeless. Look at new code.
- Using the same project key for two projects. They overwrite each other.
Summary
- A scanner sends a report to the server after each analysis.
- Issues come from rules; rules come from a quality profile; the gate decides pass or fail.
- Always separate new code from overall code.
CHECK YOUR UNDERSTANDING
3 quick questions
1. What does the scanner send to the server?
2. What is the difference between a bug and a code smell?
3. What is Clean as You Code based on?
You've finished the free preview of SonarQube & Code Quality
Upgrade to Pro to unlock the remaining 14 lessons, every practice lab and a certificate when you finish.
See plans