Continuous Inspection
of Code Quality
SonarQube: An Open Source - Code Analysis Platform
Emre Dündar
23.08.2017 – QAIst Meetup
Emre Dündar
 Release Manager @Product Development Unit
@Ericsson R&D - Turkey (2017 - ...)
 Configuration Engineer @SDLC Tools & DevOps Unit
@SoftTech (2014 - 2017)
www.linkedin.com/in/emredundar
emredundar.e@gmail.com
https://emredundar.github.io/
Continuous - X
• Continuous integration
• Continuous delivery
• Continuous testing
• Continuous deployment
• Continuous improvement
Continuous inspection
Continuous Inspection /
• A new approach to code quality management
• Code quality as a part of Software Development Life Cycle (SDLC)
• A clear view of software quality for all stakeholders
• Continuous feedback about software quality
• Obtaining the ability of better software development practices
Continuous Inspection /
... but how?
• On-the-fly: Fix issues before they exist.
• Integration: Analyse on the CI / DevOps pipeline.
• Quality Gates: Reject if not ok.
• Track issues: Track the issues on new code (who committed the issue?)
The value of continuous inspection is to find the issues
while it is easy and cheap to fix.
Continuous Inspection /
Continuous inspection of source code quality
Continuous Inspection /
... how?
Static code analysis
 Analyse source code without execution
 Generate software metrics
Software Metrics
... how to generate?
 Software metrics are generated by matching the measurable properties of software with
numbers.
... purpose?
 to measure software quality
 to find problematic units
 to predict the future of software product
Software Quality Metrics
 Subcomponents of software quality
 What & how to measure?
 Metric x Quality relations
Software Quality Model
Software Quality
Model
- McCall, J. A. (1977)
- Boehm (1978)
- Consortium for IT Software
Quality (CISQ)
- International Standards (ISO,
IEEE...)
Software Quality Metrics
Size metrics / lines of code, classes, functions, files...
Test metrics / unit tests, line coverage...
Complexity / cyclomatic complexity, complexity per function...
Duplications / duplicated blocks, duplicated lines (%)...
Issues / blocker, critical, major, minor, info / Code smells, bugs, vulnerabilities
Technical Debt /
Static Code Analysis
 Readable code
 Maintainable code
 Documented code
 Low complex code
 Coding standards
 High performance code
 Secure code
 Stable code
 Reviewed code
 Technical debt under control
 Clean code
Technical Debt
Kitchen metaphor
Day 1
Technical Debt
Kitchen metaphor
Day 2
Technical Debt
Who will clean?..
Software perspective:
Lack of time + new requests +
new bugs + ...
Does it work? Yes, go on...
Code quality must be the concern of all team,
not just some specialist.
.. there is a need for an assistant...
SonarQube is not just a tool, it is a platform.
Continuous code quality online
SonarQube: Architecture
- SonarQube Scanners don't need to be on the same network as the SonarQube Server.
- There is no communication between SonarQube Scanners and the SonarQube Database.
- SonarQube Scanners scale by adding machines.
SonarQube: Issue cycle
Languages / 20+
Java
JavaScript
PHP
Python
Web
Xml
Android
C#
C/C++ *
Objective-C *
Swift *
PL/SQL *
COBOL *
...
Overall Health
Look for general results…
Leak
Fix the leaks…
SonarQube
Scanners
 Maven
 Gradle
 Ant
 MSBuild
 Jenkins
 CLI
> mvn clean install sonar:sonar
> cd mySourceCode
> sonar-scanner -Dproject.settings=myproject.properties
SonarQube: Rules
Rulesets for each languages
3 main categories: Bugs, vulnerabilities, code smells.
Coding standards
 OWASP, CWE, CERT, MISRA... (Security vulnerabilities)
 Checkstyle (Conventions, coding rules)
 PMD (Bad practices, potential problems)
 FindBugs (Potential bugs)
 ......
http://localhost:9000/coding_rules#languages=java|severities=BLOCKER|types=BUG|tags=cert
Issues
 Code Smells
 Bugs
 Vulnerabilities
SonarQube on DevOps pipeline
SonarLint
 on-the-fly usage over IDEs
 Connect to your own
SonarQube server
 Working with online rulesets
http://www.sonarlint.org/
Pull Request
Github, TFS, Bitbucket
Quality Gates
Don’t get commits in from the
gate which brings new
vulnerabilities, high technical
debt, low code coverage…
https://next.sonarqube.com/sonarqube/quality_gates/show/7
Webhook - integrations
Trigger other systems via Webhooks
• Trigger an alerts
• Update a field
• Post a message to a chat room
• Send an e-mail
• Create a ticket
• ....
• Jira ticket
• Email
• Slack message
Demo: SonarQube
SonarQube, SonarLint, VisualStudio, VisualStudio Code, Eclipse, Gitlab, Jenkins, Slack...
References
• https://www.sonarsource.com/
• https://www.sonarqube.org/
• http://www.sonarlint.org/
• Continuous Inspection, Olivier Gaudin - https://www.sonarsource.com/resources/white-papers/continuous-
inspection.html
• Technical Debt, Patroklos Papapetrou - http://thinkapps.com/blog/tag/technical-debt/
• Metric definitions - https://docs.sonarqube.org/display/SONAR/Metric+Definitions
Contact info: www.linkedin.com/in/emredundar
emredundar.e@gmail.com
https://emredundar.github.io/
Emre Dündar

Continuous Inspection of Code Quality: SonarQube