Test Tooling

7 Best Type Checkers and Static Analyzers for Cleaner Code

Seven type checkers and static analyzers that catch errors before tests run, from mypy and Pyright to PHPStan and Semgrep.

On this page
  1. Key takeaways
  2. Quick comparison
  3. The best type checkers and static analyzers
  4. How we chose
  5. FAQ
  6. Sources

Key takeaways

  • mypy checks Python types and flags mistakes that plain unit tests would miss.
  • Pyright offers fast type checking with strong editor support for Python projects.
  • PHPStan and Psalm both bring deep static analysis to PHP codebases.
  • Semgrep lets teams search code with custom patterns beyond any single language.

Type checkers and static analyzers catch problems before a program ever runs. They read the source code and look for mismatched types, unreachable branches, and other issues that a test suite may never touch. For a team that writes a lot of code, these tools turn whole categories of bugs into editor warnings and CI failures instead of late surprises.

The tools below span several languages. Some verify types, some search for patterns, and a few do both. Each one fits a specific runtime, so the right choice depends on what a project is written in and how much of its code already carries type information.

Quick comparison

ToolBest forStarting priceFree plan
mypyStatic type checking for PythonNot includedNot included
PyrightFast type checking for PythonNot includedNot included
FlowType checking for JavaScriptNot includedNot included
SorbetType checking for RubyNot includedNot included
PHPStanStatic analysis for PHPNot includedNot included
PsalmType checking for PHPNot includedNot included
SemgrepCustom code pattern searchNot includedNot included

The best type checkers and static analyzers

1. mypy

  • Official site: https://mypy-lang.org/
  • Best for: Static type checking for Python
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Catches type bugs; good docs
  • Cons: Python only; needs annotations

mypy is the reference static type checker for Python. It reads optional type annotations and verifies that functions receive and return the types they declare, catching mismatches long before a test would fail. Because it works from annotations alone, it does not need to run the program to find problems, and it fits most Python workflows through a command line tool and editor integrations.

Teams usually add mypy to a pre-commit step or a CI job so type errors surface early, before a change is merged. The trade-off is that it only works on Python and only helps when code carries annotations, so older projects may need to add types gradually before the checker reaches its full value.

2. Pyright

  • Official site: https://github.com/microsoft/pyright
  • Best for: Fast type checking for Python
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Very fast; great editor support
  • Cons: Python only; needs types

Pyright is a fast static type checker for Python built by Microsoft. It is designed for responsiveness, so results appear quickly in editors even on large codebases, and it backs several language server features such as hover information and go-to-definition. Like other Python checkers, it works from type annotations and can run in watch mode during development.

Its speed makes it a common choice for bigger Python projects and for tooling that needs near-instant feedback while someone types. The limits are familiar: it handles only Python, and its value depends on how much of the code carries type information, so unannotated code receives fewer checks.

3. Flow

  • Official site: https://flow.org
  • Best for: Type checking for JavaScript
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Incremental; catches type bugs
  • Cons: Less popular now; config needed

Flow is a static type checker for JavaScript that analyzes code incrementally. It tracks types across a project and reports errors as files change, which keeps checks fast on larger codebases. Developers add type annotations gradually, and Flow checks the annotated parts while still reasoning about plain JavaScript where it can.

Flow was among the early type systems for JavaScript and has a well thought out design, though its usage has declined as other tools grew more popular. It needs a configuration step and a build integration, so teams usually adopt it deliberately rather than picking it up by accident.

4. Sorbet

  • Official site: https://sorbet.org
  • Best for: Type checking for Ruby
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Fast; gradual types
  • Cons: Ruby only; adoption curve

Sorbet is a type checker for Ruby that uses gradual typing. It lets teams add type signatures to parts of a codebase over time and checks those parts while leaving the rest untouched, which suits large Ruby applications that cannot be annotated all at once. It is designed to run quickly across many files, so it stays practical on big projects.

The gradual approach means a project can adopt Sorbet incrementally without a single massive rewrite. It still requires learning the signature syntax and adding tooling to the workflow, and it only applies to Ruby code, so the choice makes sense for teams already committed to that language.

5. PHPStan

  • Official site: https://phpstan.org
  • Best for: Static analysis for PHP
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Deep checks; fast
  • Cons: PHP only; config work

PHPStan is a static analyzer for PHP that performs deep checks on a codebase. It looks beyond basic syntax to find type errors, undefined methods, and other problems by analyzing how values flow through the program. The tool offers multiple levels of strictness, so a team can start with gentle checks and turn them up as the code improves.

Because it reads code rather than running it, PHPStan catches issues across files that unit tests may not connect. It is limited to PHP and usually requires some configuration of rules and paths, but once set up it runs quickly as part of a CI pipeline and gives reliable, repeatable results.

6. Psalm

  • Official site: https://psalm.dev
  • Best for: Type checking for PHP
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Strong types; auto fixes
  • Cons: PHP only; learning curve

Psalm is a static analysis and type checking tool for PHP. It supports a detailed type system, including types that go beyond PHP's built-in annotations, and it can suggest or apply fixes for some of the issues it finds. This makes it useful both for finding bugs and for cleaning up existing code over time.

Psalm is often adopted alongside a PHP test suite as an extra guard layer that runs in CI. The cost is a learning curve for its type syntax and configuration, and it only targets PHP, so the effort pays off mainly on substantial PHP applications that would otherwise lack that depth of checking.

7. Semgrep

  • Official site: https://semgrep.dev
  • Best for: Custom code pattern search
  • Starting price: Not included
  • Free plan: Not included
  • Pros: Write your own rules; fast
  • Cons: Learning the syntax; some rules paid

Semgrep is a pattern search tool that works across many languages. Teams write rules that describe a code pattern, such as a risky function call or a missing cleanup step, and Semgrep finds matches throughout a repository. Because rules are written once and reused, it goes beyond the checks baked into a single type checker.

Semgrep ships with a registry of community rules and runs quickly on large codebases. The main effort is learning the rule language well enough to write precise patterns, and some advanced rule packs come through a paid offering, though the core engine and many rules remain available for free.

How we chose

These tools cover the two main ways to catch problems before runtime: type checking and static pattern analysis. The list spans Python, JavaScript, Ruby, and PHP on purpose, because a static tool only helps if it matches the language a team already uses.

Preference went to actively maintained tools with clear documentation and a low setup bar. Each one can run in an editor or a CI job, so it fits into an existing workflow rather than demanding a new system.

FAQ

What is the difference between a type checker and a static analyzer?

A type checker verifies that values have the types a program declares, while a static analyzer looks more broadly at code patterns and structure. The two overlap, and many tools do both at once.

Do these tools replace unit tests?

They do not replace tests, they add a separate guard. Tests check behavior at runtime, while these tools read the source and catch problems before the code even runs.

Which tool should a Python team start with?

mypy is the common starting point for Python type checking, and Pyright is a strong alternative when speed and editor support matter more.

Do I need to annotate every line of code?

Gradual typing tools such as Sorbet and Flow let a team add types over time. The more code is annotated, the more the checker can verify.

Can one tool cover several languages?

Semgrep matches patterns across many languages, so it can guard a codebase that mixes runtimes, while the language-specific checkers handle deeper type work for a single runtime.

Sources