Static code scanning means running a tool over your source code without executing it, to catch bugs, security flaws, and style problems before they ship. The short version: install a scanner (Semgrep, SonarQube, or your language's linter), point it at your repository, run a baseline scan, triage the findings by severity, fix or suppress them, then wire the scan into CI so it runs on every pull request. Nothing needs to be deployed or run for the scan to work.
What You'll Need
- A code repository you have permission to scan (your own, or one you are authorised to review).
- A scanner that matches your language: Semgrep, SonarQube/SonarLint, ESLint (JavaScript/TypeScript), Bandit (Python), or the compiler's built-in warnings.
- Python 3 or Node.js on your machine for most command-line scanners, or Docker if you prefer containers.
- Write access to the repository's CI configuration if you want the scan to run automatically.
- A few minutes to triage the first run, which will almost always be noisy.
Step-by-Step
- Pick the right scanner for the job. Use a linter for style and correctness (ESLint, Ruff, Pylint), a security-focused scanner for vulnerabilities (Semgrep, Bandit, gosec), and a platform like SonarQube when you want one dashboard across many repos. You can run more than one; start with one and add later.
- Install it locally. For Semgrep:
pip install semgreporbrew install semgrep. For Bandit:pip install bandit. For ESLint:npm install --save-dev eslint. Install only from the official package registry or the vendor's own download page. - Run a first scan from the repository root. Examples:
semgrep --config auto .,bandit -r ./src,npx eslint .. Point the tool at the source directory, not your whole home folder, so it does not crawl unrelated files. - Read the output format. Most scanners print file path, line number, rule ID, severity, and a short explanation. Save the output to a file (
--output results.jsonor similar, depending on the tool) so you can sort and compare runs. - Triage the first run. Expect a long list. Sort by severity, then by whether the flagged code is reachable from user input. Fix real issues; mark false positives with an inline suppression comment (for example
# nosecin Bandit, or// eslint-disable-next-linein ESLint) and a short reason. Never suppress a finding you have not read. - Fix and re-run. Change one category at a time (for example, all injection findings first), re-run the scan, and confirm the count drops. Commit fixes in small batches so reviews stay readable.
- Add a config file. Most scanners support a project config (for example
.semgrep.yml,.bandit, oreslint.config.js) where you exclude vendored code, generated files, and test fixtures, and enable or disable specific rules. Commit it so every developer gets the same behaviour. - Wire it into CI. Add a job to your pipeline (GitHub Actions, GitLab CI, Jenkins, or whatever you use) that runs the same command and fails the build on new high-severity findings. Gate on new findings rather than the full historical backlog, or the build will never pass.
- Review findings on every pull request. Many scanners offer a diff-aware mode that only reports issues introduced by the change. That keeps the signal high and stops reviewers from ignoring the tool.
- Schedule a periodic full scan. A weekly or nightly run catches issues that appear as rules are updated, even when nobody touched the affected file.
Common Mistakes
- Scanning everything. Pointing the tool at
node_modules,vendor, or build output produces thousands of findings you cannot fix and did not write. Exclude them in config. - Treating the first run as a to-do list. The initial backlog is often hundreds of items. Fix high-severity issues, suppress confirmed false positives with a reason, and gate on new findings going forward.
- Suppressing without reading. A blanket disable at the top of a file hides real bugs later. Suppress line by line, with a comment explaining why.
- Running only locally. A scan that depends on one developer remembering to run it will be skipped. Put it in CI.
- Ignoring rule updates. Scanners add rules over time. A clean scan today can show new findings next month without any code change; that is expected, not a regression.
- Confusing static scanning with dependency scanning. Static analysis reads your code; software composition analysis reads your lockfiles and manifests. You usually want both.
Tips
- Start with one scanner and one language. Adding three tools on day one buries the team in duplicate findings.
- Keep a written triage policy: which severities block a merge, which are advisory, and who decides on suppressions.
- Run the scanner in the same container or language version your CI uses, so results match what developers see.
- Store scan results as build artifacts so you can compare runs and prove a finding was fixed.
- Review the rule set quarterly. Rules you disabled for good reasons last year may no longer apply.
- Teach the team to read one finding properly rather than skimming fifty. A single well-understood rule beats a wall of warnings.
Troubleshooting
The scan is extremely slow. Check what it is crawling. Most slowness comes from scanning dependency folders, large binaries, or the entire home directory. Add exclusions and re-run.
Too many false positives. Tighten the rule set, exclude test and generated code, and check whether the scanner is running with the right language parser for your files (for example, JSX or TypeScript needs the correct plugin).
The CI job fails but local runs pass. Compare tool versions, config files, and the working directory. A scanner run from a subfolder sees a different set of files than one run from the repo root.
Findings appear that were not there yesterday. The rule set or the scanner version likely updated. Pin the scanner version in CI if you need reproducible results, and review new rules before enabling them.
The tool crashes on a file. Check the file for very long lines, unusual encodings, or generated content. Exclude it and report the crash to the tool's issue tracker rather than working around it silently.
If that did not work, uninstall and reinstall the scanner from the official source, delete any cached rule bundles, and run it against a tiny sample project to confirm the install is healthy before pointing it at your real repository.
Frequently Asked Questions
Does static scanning run my code?
No. It parses and analyses source files without executing them, which is why it is safe to run on untrusted code and fast enough for every commit.
Is static scanning the same as a linter?
Not exactly. Linters focus on style and simple correctness; static analysis scanners also look for security patterns, data-flow issues, and risky API use. Many tools do both.
Can it find every security bug?
No. It catches patterns it has rules for. Logic flaws, design mistakes, and issues that depend on runtime configuration will get through, which is why it complements testing and review rather than replacing them.
Should I scan third-party code?
Generally no, unless you have vendored and modified it. Exclude dependencies and scan them with a dependency scanner instead.
How often should scans run?
On every pull request for new findings, plus a scheduled full scan weekly or nightly to catch rule updates and drift.
Do I need a paid tool?
No. Open-source scanners cover most languages well. Paid platforms add dashboards, policy management, and cross-repo reporting, which matter more as a team grows.