Skip to content

Commit 6b05540

Browse files
authored
linter: adding cyclomatic complexity (#252)
1 parent f980dd0 commit 6b05540

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/content/docs/build/smart-contracts/linter.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,22 @@ public fun get_refs(): vector<ConstructorRef> {
444444
// ... code that returns vector with ConstructorRef
445445
}
446446
```
447+
448+
## Experimental Checks
449+
450+
### `cyclomatic_complexity`
451+
452+
Cyclomatic complexity measures the number of linearly independent execution paths through a function. A high value generally correlates with code that is harder to test and maintain.
453+
454+
This linter performs an approximation while traversing the Move expression tree:
455+
456+
1. The complexity score starts at **1**.
457+
2. The score is incremented for each control-flow decision point found:
458+
- +1 for each `if`
459+
- +1 for each `else if`
460+
- +1 for each `loop`, `while`, or `for`
461+
- +1 for each `break` or `continue`
462+
- +1 for each `return` statement that is not the final expression in the function
463+
- +n where n = (number of match arms - 1)
464+
465+
When the accumulated score exceeds the default threshold (currently **10**), the linter emits a diagnostic suggesting that the function be simplified or decomposed.

0 commit comments

Comments
 (0)