Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit e5330d3

Browse files
committed
Add nested_if documentation
1 parent a3a7a7f commit e5330d3

File tree

1 file changed

+25
-3
lines changed
  • apps/nextra/pages/en/build/smart-contracts

1 file changed

+25
-3
lines changed

apps/nextra/pages/en/build/smart-contracts/linter.mdx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt
1818
Checks for patterns that look like overflow checks done in a C style:
1919
```move
2020
// Overflow check
21-
if (x > x + y) {
21+
if (x > x + y) {
2222
abort 1;
2323
};
2424
2525
// Underflow check
26-
if (x < x - y) {
26+
if (x < x - y) {
2727
abort 1;
2828
};
2929
```
30-
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
30+
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
3131

3232
### `almost_swapped`
3333
Checks for expression patterns that look like a failed swap attempt and notifies the user. These patterns are likely erroneous code. This currently only detects simple access patterns such as assignments to a variable or a field of a struct. Examples include:
@@ -118,6 +118,28 @@ Checks for patterns where there are needless references taken when accessing a f
118118
- `(&s).f` can be simplified to `s.f`
119119
- `(&mut s).f = 42;` can be simplified to `s.f = 42;`
120120

121+
### `nested_if`
122+
123+
Checks for nested if statements that can be simplified using the `&&` operator. This lint identifies patterns where an inner if statement with no else branch is contained within an outer if statement that also has no else branch.
124+
125+
```move
126+
if (a) {
127+
if (b) {
128+
// some code
129+
}
130+
}
131+
```
132+
133+
This pattern can be simplified to:
134+
135+
```move
136+
if (a && b) {
137+
// some code
138+
}
139+
```
140+
141+
The simplified version is more readable and avoids unnecessary nesting while maintaining the same logical behavior.
142+
121143
### `nonminimal_bool`
122144

123145
Check for boolean expressions that can be simplified when a boolean literal (either `true` or `false`) is part of a binary or unary boolean operator. Examples:

0 commit comments

Comments
 (0)