Guides / Code quality
Code quality: what it is, how to measure it, where to start
- median code health, out of 10
- 7.14median code health, out of 10
- median health of the files that change most
- 4.86median health of the files that change most
- of files hold a function above complexity 10
- 23.3%of files hold a function above complexity 10
- of bug-fixed files sit in the least-healthy 20%
- 60%of bug-fixed files sit in the least-healthy 20%
Medians across public GitHub repositories with 1,000+ stars, production files only. Read the methodology.
Technical debt
The cost of shortcuts that make the next change slower. Find it, price it, and decide what to pay down first.
Code complexity
How many paths run through a function and how deeply they nest. The single most used code quality number.
Code smells
Patterns that are not bugs yet but make bugs likely: long methods, god classes, tangled imports.
Linters
Rule checks that run on every save and every commit. The cheapest code quality gate there is.
Static analysis
Reading code without running it: linters, type checkers, security scanners and code health tools.
Refactoring
Changing structure without changing behavior. The payoff is highest where complex code also changes often.
Dead code
Files and exports nothing reaches. Safe deletions shrink every other number on this page.
Test coverage
Which lines your tests run. More useful when you know which untested files matter most.
Coding standards and clean code
The conventions a team agrees on, and the habits that keep code readable after the author moves on.
Dependencies and structure
How files and packages lean on each other. Cycles and hub files make every change reach further.
Bugs and defects
Where bugs come from, and whether code quality scores point at the files that get fixed.
Code quality with coding agents
Agents write code faster than people review it. Keeping quality up means checks the agent runs itself.
Measuring code quality
Turning the topics above into one score per file, and comparing it across repositories.
By language
Linters, static analysis and code quality data per language.
Questions
What people ask before they try it.
What is code quality?
Code quality is how easily code can be read, changed and trusted. High-quality code has small, clear functions, few hidden dependencies, tests on the parts that matter and no dead weight, so a change in one place does not break another. It is a property of the whole codebase, measured file by file.
How do you measure code quality?
Combine a few signals instead of trusting one. Cyclomatic or cognitive complexity per function, code smells such as long methods and god classes, dead code, test coverage on the files that change most, churn and ownership from git history. Linters and static analyzers check rules; a code health score rolls the signals into one number per file so you can rank where to work.
What does good code quality look like in numbers?
In 195 public GitHub repositories with 1,000+ stars, the median repository scores 7.14 out of 10 on code health, and its most-changed files score 4.86. Half of all files have a worst function of complexity 4 or less, and 23.3% have one above 10. Those medians are a fair baseline to compare your own repository against.
What is the difference between a linter and static analysis?
A linter is one kind of static analysis tool: it checks each file against named rules for bugs and style. Static analysis is the wider family of tools that read code without running it, including type checkers, security scanners, dependency and dead-code analysis and code health scoring, some of which look across the whole repository instead of one file.
How do I improve code quality in an existing codebase?
Start where poor quality costs the most: files that are both complex and changed often. In the median repository, 10% of files take 68% of recent changes, and the least-healthy 20% of files hold 60% of the files that needed a bug fix. Delete dead code first, add tests to the busiest untested files, then refactor the worst hotspots one at a time.
See where your code stands.
Index a repository free and get complexity, dead code, hotspots and a health score per file. Or open a live repo first.