Guide

Code scanning: Essential guide for development teams

Table of contents

Try SonarQube for free

What is code scanning?

Code scanning is an automated process that uses static analysis to examine source code without executing it to identify potential bugs, security vulnerabilities, compliance issues and violations of coding standards.

Think of code scanning as having an expert reviewer who never gets tired and can check millions of lines of code in minutes. It operates deterministically: the same code will always produce the same results. This makes it a reliable foundation for maintaining code quality across teams and over time.

Modern code scanning tools go beyond simple syntax checking. It understands the semantic meaning of code, traces data flows through applications, and identifies complex issues that might take human reviewers hours or days to spot. This automated approach has become essential as software complexity grows and deployment cycles accelerate.

Why is code scanning important?

In modern software development, speed is everything. But as teams accelerate, the risk of introducing critical bugs and security vulnerabilities grows exponentially. Manual reviews, while valuable, simply cannot keep pace with the volume and complexity of code changes, creating a gap where serious issues can slip into production.

Code scanning closes this gap by acting as an automated, vigilant safety net. It proactively identifies vulnerabilities and bugs in source code long before they are released, preventing them from ever reaching production systems where the cost and impact are highest.

This practice is central to the "shift left" philosophy in the Software Development Lifecycle (SDLC),. By finding and fixing problems while a developer is still working on the code—rather than weeks later after a security incident—teams dramatically lower the cost of fixes. Ultimately, integrating code scanning leads to a more secure and efficient development process, improves overall application quality, reduces security risks, and helps teams meet critical compliance requirements.

The limitations of manual review in modern development

In today's software landscape, where applications are built rapidly and deployed continuously, manual review alone cannot keep pace with the volume and complexity of code changes. Consider the numbers: a typical development team might push dozens of commits daily, each containing hundreds or thousands of lines of code. Even the most diligent reviewer, spending 10 minutes per 100 lines of code, would need hours just to review a single day's work. Multiply this across multiple team members, and manual review becomes a full-time job that still can't cover everything.

But volume is only part of the problem. Modern applications involve intricate interactions between components, where a security vulnerability might stem from how data flows across five different functions, three API calls, and two database queries in four different files. Tracking these complex data flows manually requires holding an entire system's architecture in your head while examining each line of code, a cognitive load that even experienced developers would struggle to maintain consistently.

Human reviewers also face the challenge of knowledge limitations. Security vulnerabilities evolve constantly, with new attack vectors discovered weekly. No single developer can stay current with every CVE, every OWASP guideline update, and every framework-specific security consideration across the various programming languages in an organization. A Java expert is likely to miss a React-specific XSS pattern, while a frontend developer wouldn't recognize a subtle SQL injection vulnerability in backend code.

Perhaps most critically, human review suffers from inconsistency. The same reviewer might catch an issue on Monday morning but miss an identical problem on Friday afternoon. Additionally, different reviewers apply different standards, leading to security gaps where one team's "acceptable" might be another team's "critical vulnerability." Fatigue, time pressure, and context switching all degrade review quality, creating windows where serious reliability and security issues slip through.

Early detection saves money and time

Studies consistently show that fixing a bug during development costs 10-100 times less than addressing it after it has reached production. A developer fixing a potential SQL injection vulnerability in their IDE takes five minutes; a security team patching it in production after a data breach can take weeks and cost millions in fines and lost trust. Code scanning catches issues at the earliest possible stage while developers are still coding. When integrated into IDEs, code scanning can alert developers to problems before the code is even committed, providing real time feedback that prevents defects from leaving the workstation.

Consistency across development teams

Unlike manual reviews that vary based on reviewer expertise and attention, code scanning provides consistent, repeatable analysis. Every piece of code is evaluated against the same rules, ensuring uniform quality standards across your entire codebase. This consistency is particularly valuable in large organizations where multiple teams contribute to the same projects and rely on pull requests as a standardized collaboration point.

Protection during rapid development

With AI-powered development tools accelerating code generation, automated scanning becomes essential for maintaining quality at speed. While AI assistants help developers write code faster, they can amplify problematic patterns. Code scanning provides immediate feedback on every commit, ensuring the acceleration benefits of AI-assisted development don't compromise security or reliability, ideally catching issues in the IDE while coding, with protection extending through the entire CI/CD pipeline.

Regulatory compliance requirements

Industries subject to regulations like HIPAA, PCI DSS, and GDPR must demonstrate that secure coding practices have been followed. Code scanning provides auditable evidence of security controls, and the documentation needed to satisfy regulatory requirements. Without automated code scanning, meeting these compliance requirements becomes nearly impossible at scale. Complementary practices like software composition analysis (SCA) also help document and mitigate third-party dependency risks across a wide range of ecosystems. 

How does code scanning work?

Step 1: Parsing and syntax analysis

The scanning engine begins by parsing source code to create an Abstract Syntax Tree (AST), which is a hierarchical representation of the code's structure. This tree captures every element of the code: variables, functions, classes, control structures, and their relationships. During parsing, the scanner:

  • Validates syntax correctness
  • Builds a structured model for deeper analysis
  • Prepares the code for semantic evaluation

Step 2: Semantic analysis

Once the AST is constructed, the scanner performs semantic analysis to understand what the code actually does, not just how it's structured. This includes:

  • Type checking: Verifying that variables and functions are used according to their declared types
  • Symbol resolution: Tracking variable scope and ensuring references are valid
  • Control flow analysis: Mapping the execution paths through the code
  • Data flow analysis: Following how data moves through the application to identify potential security issues

Step 3: Applying rules

The scanner applies sophisticated rules that act like expert reviewers examining your code. These rules are carefully crafted algorithms that recognize problematic patterns. Think of them as encoded expertise from security researchers and software architects. A rule might look for SQL queries built through string concatenation (indicating the potential for SQL injection), or detect when user input flows to dangerous functions without validation.

Step 4: Results prioritization and reporting

Not all issues are equal. Once the scanner has identified potential problems, it evaluates and prioritizes them to help developers focus on what matters most. Scanners assess findings based on severity levels (Blocker, High, Medium, Low, Info), how recently the issue was introduced, what aspects of an application it affects (reliability, maintainability, security).

Results are then presented with detailed explanations, code examples, and remediation guidance that provide actionable insights at the moment developers need them.

What types of issues does code scanning detect?

Code scanning identifies a comprehensive range of issues across multiple categories, each critical to software quality and security. The examples below represent just a fraction of what modern scanning tools can detect. Sophisticated scanners contain thousands of rules covering everything from subtle cryptographic weaknesses to framework-specific anti-patterns.

Security issues (Vulnerabilities)

  • Injection flaws: SQL, LDAP, XPath, and command injection vulnerabilities where untrusted data is executed
  • Authentication issues: Weak password storage, session fixation, insufficient authentication mechanisms
  • Data exposure: Unencrypted sensitive data, information leakage through error messages, insecure direct object references
  • Security misconfigurations: Default passwords, verbose error handling, unnecessary services enabled
  • Secrets in code: Hard-coded API keys, passwords, and cryptographic keys that should never be in source control

Reliability issues (Bugs)

  • Null pointer dereferences: Attempts to use null references that cause application crashes
  • Resource leaks: Unclosed database connections, file handles, or network sockets
  • Concurrency issues: Race conditions, deadlocks, thread safety violations
  • Logic errors: Infinite loops, unreachable code, incorrect operator usage
  • Exception handling: Swallowed exceptions, incorrect error propagation

Maintainability issues (Code Smells)

  • Complexity metrics: Functions or classes that are too complex to maintain effectively
  • Code duplication: Repeated code blocks that should be refactored
  • Code smells: Patterns indicating deeper design problems
  • Documentation issues: Missing or outdated comments for complex logic
  • Naming conventions: Inconsistent or unclear variable and function names

Other quality issues

  • Deprecated API usage: Calls to outdated libraries or functions
  • Performance anti-patterns: Inefficient algorithms, unnecessary database calls
  • Architectural violations: Code that breaks established design patterns
  • Test coverage gaps: Areas of code without adequate testing

Code scanning for teams

In collaborative development settings, code scanning becomes even more critical. It serves as an objective arbiter of code quality and a protective barrier for your main branch, enhancing developer workflows and enforcing consistent standards through pull requests.

Automated gates in DevOps workflows

When integrated into continuous integration pipelines, code scanning creates automated checkpoints that empower developers with immediate feedback. Rather than waiting for security teams to find issues weeks later, developers get instant notifications while the context is still fresh. The best implementations catch issues in the IDE before code is even committed, with a safety net that prevents anything problematic from reaching production. Embedding scanning into your CI/CD Pipeline ensures that automated scans run consistently and surface actionable insights in real time.

These gates can:

  • Block pull requests containing issues
  • Enforce coverage/duplication thresholds for new code
  • Provide a clear go/no-go signal for the deployability of a branch

Standardization across teams

Code scanning ensures consistent quality standards whether code is written in San Francisco, Bangalore, or Berlin. Having consistent standards throughout an organization empowers developers to move between teams confidently, and lets them focus on solving business problems rather than having to learn a new set of quality standards for each project.

Objective metrics for decision making

Code scanning replaces subjective quality discussions with clear, measurable standards. At the organizational level, leaders can identify which teams or projects are struggling with security vulnerabilities or technical debt and allocate resources accordingly. No more flying blind until production issues surface. For development teams, pull requests are approved based on objective criteria rather than reviewer preferences. The code either passes the security rules or it doesn't; test coverage either meets the 80% threshold or it falls short. This transparency means everyone knows exactly what standards their code must meet and where the remaining security quality and security risks are concentrated.

Code scanning and SonarQube

SonarQube brings together all the code scanning capabilities described above into a unified platform that integrates seamlessly with your existing development workflow. With support for over 35 programming languages and frameworks, SonarQube's scanning engine analyzes your entire codebase—from frontend JavaScript to backend Java, from infrastructure-as-code to COBOL. SonarQube’s sophisticated detection rules identify vulnerabilities, bugs, and code smells with exceptional accuracy while minimizing false positives that waste developer time. 

Central to this process is the Quality Gate, a core feature of SonarQube that acts as a go/no-go checkpoint in your development pipeline. The Quality Gate defines a set of pass/fail criteria for your code, such as "no new critical vulnerabilities," "80% test coverage on new code," or "no new bugs." If the code analysis does not meet these conditions, the Quality Gate fails, which can automatically prevent a pull request from being merged or a build from being released. This enforces your quality standards on every commit, ensuring that only clean, secure, and reliable code makes it to production.

Whether you're working in your IDE using SonarQube IDE, reviewing pull requests, or monitoring your main branch, SonarQube provides consistent, actionable insights that help developers fix issues when they're easiest and least expensive to address.

Frequently asked questions

  • Suivez SonarSource sur Twitter
  • Suivez SonarSource sur Linkedin
language switcher
Français (French)
  • Documentation juridique
  • Trust Center

© 2008-2024 SonarSource SA. Tous droits réservés. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD et CLEAN AS YOU CODE sont des marques déposées de SonarSource SA.