You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: apps/nextra/pages/en/build/smart-contracts/linter.mdx
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,16 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt
18
18
Checks for patterns that look like overflow checks done in a C style:
19
19
```move
20
20
// Overflow check
21
-
if (x > x + y) {
21
+
if (x > x + y) {
22
22
abort 1;
23
23
};
24
24
25
25
// Underflow check
26
-
if (x < x - y) {
26
+
if (x < x - y) {
27
27
abort 1;
28
28
};
29
29
```
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.
31
31
32
32
### `almost_swapped`
33
33
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:
@@ -65,6 +65,22 @@ Checks for binary operations where both operands are the same, which is likely a
65
65
66
66
This lint does not catch cases where the operands are vector access.
67
67
68
+
### `find_unnecessary_casts`
69
+
70
+
Checks for unnecessary type casts where the source expression already has the same type as the target type. These casts are redundant and can be removed to improve code readability.
71
+
72
+
For example:
73
+
```move
74
+
let x: u64 = 42;
75
+
let y = x as u64; // unnecessary cast, x is already u64
76
+
```
77
+
78
+
The above can be simplified to:
79
+
```move
80
+
let x: u64 = 42;
81
+
let y = x; // cast removed
82
+
```
83
+
68
84
### `known_to_abort`
69
85
70
86
Checks for expressions that will always abort at runtime due to known constant values that violate runtime constraints. This lint helps identify code that will deterministically fail before it reaches production.
0 commit comments