Weighted Methods per Class
The sum of cyclomatic complexity across all methods of a class.
Overview
Weighted Methods per Class (WMC) is a class-level metric that captures overall class complexity by summing the complexity of every method. Classes with high WMC are harder to understand, test, and maintain. A very high WMC may indicate a God Class.
Formula
Each method's contribution equals its cyclomatic complexity (minimum 1). A class with three trivial methods and no branching has WMC = 3.
What tsmetrics includes in WMC
tsmetrics sums the CC of the following method kinds:
- Regular instance and static methods (
method_definition) - Constructors
- Getter and setter accessors
- Abstract method signatures (
abstract_method_signature)
Arrow function class fields are not included as WMC contributors, because they are tracked as functions in the function table rather than as class methods.
Thresholds
| Severity | Default value | Config key |
|---|---|---|
| warning | 20 | wmc.warning |
| error | 50 | wmc.error |
thresholds: wmc: warning: 15 error: 40
Interpretation
| WMC range | Interpretation |
|---|---|
| 1 – 19 | Reasonable class complexity |
| 20 – 49 | High complexity; consider splitting responsibilities |
| 50+ | Very high complexity; strong refactoring candidate |
Example
class OrderProcessor { constructor() {} // CC=1 validate(order: Order) { // CC=3 (2 ifs) if (!order.items.length) return false; if (!order.customer) return false; return true; } process(order: Order) { // CC=4 (3 branches) if (!this.validate(order)) return; if (order.isPriority) { /* ... */ } else { /* ... */ } } } // WMC = 1 + 3 + 4 = 8
Usage in detection strategies
- God Class — WMC > 47 is one of three required conditions
JSON field
In JSON output, the field is named wmc on each class record.
References
- Chidamber, S. R. & Kemerer, C. F. (1994). A Metrics Suite for Object Oriented Design. IEEE Transactions on Software Engineering.