Skip to content
BENIBIX Learn

Static Analysis

Development🧪 Testing & QualityCode Quality

Also known as Static Code Analysis, Static Checking, SAST

Checking code for mistakes just by reading it. It is never run.

Think of it like

Think of it like a spell checker. It reads your writing and marks mistakes before anyone sees them.

Example

Jack saves a file, and the type checker flags line 2 at once. He has put the text ten into a variable meant for numbers.

Why it matters

It is the cheapest check there is. It runs on every save and finds whole kinds of bug for free.

Definition

Static analysis is checking code for problems without running it. A tool reads the code and looks for mistakes and risky habits. Linters like ESLint do this. So do type checkers, like the one in TypeScript. Some tools look for safety holes, like passwords left in code. It finds many bugs in seconds, before any test runs.

Example code

console
$ npx tsc --noEmit price.ts
price.ts(2,1): error TS2322: Type 'string' is not assignable to type 'number'.
The checker read the file, never ran it, and found the bug.

Common mistake

Turning off every warning that gets in the way. Fix them, or switch off just that rule, with a reason written down.

Key takeaways

  1. 1
    Reads, never runs. Checks the source.
  2. 2
    Linters and type checkers. The common kinds.
  3. 3
    Before any test. Seconds, on every save.