On this page
Static code analysis is the automated examination of source code without running it, to find bugs, security vulnerabilities and quality problems. A static analyzer parses your code, builds a model of it (a syntax tree, a control-flow graph, sometimes a call graph), and checks that model against rules.
Because nothing executes, it runs on every commit in seconds and needs no test environment. It also reports on code paths no test has ever reached.
How static code analysis works
A static analyzer turns source text into structure, then looks for patterns in that structure. The steps are the same across tools, whatever the language.
- Parse. The code becomes an abstract syntax tree (AST), so the tool knows that
x = f(y)is an assignment calling a function, not a string of characters. - Model. The tool builds extra views on top of the tree: a control-flow graph (which statements can follow which), a data-flow view (where a value came from and where it goes), and for some tools a call graph.
- Check. Rules run against the model. A rule might say "a value from user input must not reach a SQL query without passing through a sanitizer", or "a function must not exceed a cyclomatic complexity of 15".
- Report. Each match becomes a finding with a file, a line, a rule ID and a severity.
The academic term is static program analysis. The OWASP Foundation page on static code analysis covers the security side in detail.
What are the types of static analysis?
Most tools you will meet do one of four jobs. Many products bundle two or more.
| Type | What it checks | Typical findings | Examples |
|---|---|---|---|
| Linting and style | Syntax patterns, formatting, suspicious constructs | Unused variable, unreachable branch, shadowed name | ESLint, Ruff, Pylint, golangci-lint |
| Type checking | Whether values are used consistently with their declared or inferred types | Passing a string where an int is expected, possible null dereference | TypeScript, mypy, Pyright |
| Security scanning (SAST) | Data flow from untrusted input to dangerous operations, hard-coded secrets, weak crypto | SQL injection, path traversal, leaked key | Semgrep, CodeQL, SonarQube Server, Fortify |
| Complexity and maintainability | Structural metrics of functions and files | Cyclomatic complexity over a threshold, long function, duplication | SonarQube Server, CodeScene, Qlty, repowise |
Scroll the table sideways to see every column.
Linters are the entry point: they are fast, configurable and usually already in the editor. Type checkers catch a whole class of bugs by proving that values are used as declared. SAST (static application security testing) specializes in vulnerabilities and is the part most teams add for compliance. Complexity metrics feed the maintainability side: they flag code that is hard to read, test or change. If you are new to those numbers, cyclomatic vs cognitive complexity explains how they differ, and the code smell glossary entry lists the patterns they point at.
For a ranked list of products by category, language and price, see best static analysis tools for large codebases.
A static analysis example
Here is a short Python function a linter and a type checker would both flag.
def apply_discount(order, rate):
total = order.total
if rate > 1:
return total
discounted = total * (1 - rate)
return total # bug: returns the original, discounted is never used
A linter such as Ruff reports that discounted is assigned and never used (rule F841). That one finding is the entire bug. No test had to exist, and the function never had to run. You can reproduce it:
pip install ruff
ruff check discount.py
Security rules work the same way at larger scale: they follow request.args["id"] through assignments and function calls and report when it arrives at cursor.execute(...) unescaped.
Static analysis vs dynamic analysis
Static analysis reads code and dynamic analysis runs it. They find different things, which is why mature pipelines use both.
| Static analysis | Dynamic analysis | |
|---|---|---|
| Needs the code to run | No | Yes |
| When it runs | Editor, commit, pull request | Test suite, staging, production |
| Finds | Patterns that are wrong in any execution: injection paths, unused values, type errors | Behavior that depends on real inputs: crashes, race conditions, memory leaks, slow queries |
| Coverage | Every path it can model, including ones no test reaches | Only the paths that actually executed |
| False positives | Common, because it reasons about possible behavior, not observed behavior | Rare, because what it reports happened |
| Examples | ESLint, CodeQL, mypy | Unit tests, fuzzers, profilers, DAST scanners |
Scroll the table sideways to see every column.
What static analysis cannot tell you
A static analyzer answers "does this code match a bad pattern?". It does not answer "does this matter?", and the second question is the one a team has to act on.
Three limits follow from how rule-based tools work.
- They see one file or function at a time. A rule can flag a function as complex. It cannot tell you that the function sits in the most-imported file in the repo, or that nothing calls it at all.
- They have no history. The same finding in a file untouched for two years and in a file changed daily gets the same severity. Change frequency, past bug fixes and who owns the file are outside the model.
- They produce volume. A first scan on a mature codebase can return thousands of findings, and a team that cannot rank them stops reading them.
The data shows how uneven the cost is. We analysed 195 of the most-starred public repositories indexed on repowise.dev (1,000+ GitHub stars each, 253,688 production source files, November 2026). In the median repo, 10% of production files absorb 68% of line churn over 90 days. Median code health is 7.1/10 across the cohort, but median hotspot health, the score over the files that change most, is 4.9/10. In 174 of 186 repos (94%), hotspot files score below the repo average.
Defects follow the same pattern. In the median repo, the least-healthy 20% of files hold 60% of the files that needed a bug fix in the last 180 days. A static analyzer that reports the same finding at the same severity everywhere sends a developer to the wrong file about as often as the right one. For the method, see what is technical debt and our code health research.
Rule-based vs graph-based static analysis
Rule-based analysis checks code against a catalogue of patterns. Graph-based analysis adds a model of the whole repository: who imports whom, who calls whom, who changes with whom. The two answer different questions and work well together.
| Rule-based (linters, SAST, SonarQube Server) | Graph-based (repowise) | |
|---|---|---|
| Unit of analysis | A file, function or data-flow path | The whole repo as a dependency and call graph |
| Question it answers | "Is this code wrong?" | "Which code is risky to change, and what breaks if I do?" |
| Inputs | Source text, rule set | Source, import and call graph, git history, ownership, tests |
| Output | A list of findings by rule | Files ranked by health, change risk and blast radius |
| Strength | Precise, well-understood rules per language and vulnerability class | Prioritization: findings weighted by churn, bug history and reach |
Scroll the table sideways to see every column.
repowise adds that second layer on top of what your linters and SAST already do. repowise health scores every file from 0 to 10 and lists the ones where the score and the change activity overlap. Indexing (repowise init and repowise update) records secrets and risky patterns, repowise security scan --history walks every past revision for leaked secrets, and repowise security check origin/main...HEAD gates a pull request on what the change adds. Dead code (unreachable files, unused exports, unused packages) comes from the import graph, which a single-file linter cannot see: 182 of 190 repos in the dataset (96%) have at least one finding. The analysis is described in the code health feature page, and the data on circular imports (89% of repos have at least one group) sits in the same dataset.
How to start with static code analysis
Adopt it in the order that gives the fastest signal for the least noise.
- Turn on the linter and type checker your language already has. ESLint with TypeScript, Ruff or mypy for Python,
go vetand golangci-lint for Go. Run them in the editor and in CI. - Fail the build only on new findings. Gate on what a pull request adds, not on the backlog. This keeps the signal clean and stops the first scan from blocking everyone.
- Add a SAST tool for security. Semgrep and CodeQL are common choices; SonarQube Server covers security alongside quality. Compare options in SonarQube alternatives.
- Rank the backlog by where you work. Sort existing findings by churn and bug history so the first hour of cleanup lands on files that pay it back. Prioritize technical debt walks through that ordering.
- Re-run on a schedule. Static results drift as code changes; track the trend, not a single number.
Common pitfalls
- Treating every finding as equal. Severity labels come from the rule, not from your codebase. A "critical" in dead code is less urgent than a "minor" in the payment path.
- Switching on every rule at once. Start with the rules that catch real bugs in your stack and add others as the team clears the first set.
- Suppressing instead of fixing. A
# noqaor// eslint-disablethat nobody revisits turns a signal into permanent noise. Require a reason and a date. - Mixing up coverage and analysis. Test coverage measures what tests executed. Static analysis does not depend on tests at all, so one does not substitute for the other.
FAQ
- What is static code analysis in simple terms?
- It is a tool that reads your source code and flags likely bugs, security holes and quality problems without running the program. Think of it as an automated proofreader for code: it checks the text against known bad patterns, so it can run on every commit.
- What are the main types of static code analysis?
- The four common kinds are linting and style checks, type checking, security scanning (SAST), and complexity or maintainability metrics. Most teams run a linter and a type checker by default, then add SAST for security and a metrics tool for maintainability.
- What is the difference between static and dynamic code analysis?
- Static analysis examines code without executing it and covers every path it can model. Dynamic analysis observes the program while it runs, so it finds runtime behavior such as race conditions and memory leaks but only on the paths that executed. Use both: in our count of common coding errors across 106,106 real bug fixes, the bugs that reach git history are mostly the logic and environment errors neither kind of tool flags on its own.
- What is the difference between SAST and static code analysis?
- SAST (static application security testing) is static code analysis aimed at security vulnerabilities such as injection and hard-coded secrets. Static code analysis is the wider category and also includes linting, type checking and code quality metrics.
- Can AI be used for static code analysis?
- Yes. AI code review tools read a diff or a file and flag problems in plain language, and they can catch issues that fixed rules miss. They are not deterministic, so most teams keep rule-based analyzers as the gate and use AI review for context and explanation on top.
- What is the best static code analysis tool?
- It depends on language and goal. ESLint, Ruff and golangci-lint cover linting; Semgrep and CodeQL cover security; SonarQube Server covers both quality and security across many languages. The roundup of static analysis tools for large codebases compares them by language, price and scale.
- Is SonarQube a static code analysis tool?
- Yes. SonarQube Server is a static analysis platform that runs rule-based checks for bugs, vulnerabilities and code smells, and gates builds with quality gates. See SonarQube alternatives for how it compares with other tools.
- What is SCA vs SAST?
- SAST scans your own source code for vulnerabilities. SCA (software composition analysis) scans the third-party dependencies you pull in, and reports known vulnerabilities and license issues in them. SAST checks code you wrote; SCA checks code you imported. Most security programs run both.
- What are the three main types of static code analysis techniques?
- Three techniques underlie most tools: pattern matching on the syntax tree (linters), control-flow analysis (which paths can run), and data-flow analysis (where a value comes from and where it goes, used for taint tracking in security scanners).



