From e5330d38039fc2e94265e9c553fe16fbd59de74c Mon Sep 17 00:00:00 2001 From: Jose Garcia Crosta Date: Mon, 14 Jul 2025 14:58:18 -0300 Subject: [PATCH] Add `nested_if` documentation --- .../pages/en/build/smart-contracts/linter.mdx | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/nextra/pages/en/build/smart-contracts/linter.mdx b/apps/nextra/pages/en/build/smart-contracts/linter.mdx index d606dd102..825e1abeb 100644 --- a/apps/nextra/pages/en/build/smart-contracts/linter.mdx +++ b/apps/nextra/pages/en/build/smart-contracts/linter.mdx @@ -18,16 +18,16 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt Checks for patterns that look like overflow checks done in a C style: ```move // Overflow check -if (x > x + y) { +if (x > x + y) { abort 1; }; // Underflow check -if (x < x - y) { +if (x < x - y) { abort 1; }; ``` -This pattern in Move does not make sense, as it either aborts immediately or is always true/false. +This pattern in Move does not make sense, as it either aborts immediately or is always true/false. ### `almost_swapped` 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 - `(&s).f` can be simplified to `s.f` - `(&mut s).f = 42;` can be simplified to `s.f = 42;` +### `nested_if` + +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. + +```move +if (a) { + if (b) { + // some code + } +} +``` + +This pattern can be simplified to: + +```move +if (a && b) { + // some code +} +``` + +The simplified version is more readable and avoids unnecessary nesting while maintaining the same logical behavior. + ### `nonminimal_bool` 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: