Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] List of Additional Aptos Move Lint Checks #15221

Open
vineethk opened this issue Nov 7, 2024 · 0 comments
Open

[Feature Request] List of Additional Aptos Move Lint Checks #15221

vineethk opened this issue Nov 7, 2024 · 0 comments
Labels
enhancement New feature or request move-linter Issues related to the Move Linter stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@vineethk
Copy link
Contributor

vineethk commented Nov 7, 2024

🚀 Feature Request

Below is a list of additional checks that we would like to add to aptos move lint. Please feel free to comment if you would like any of these implemented sooner rather than later, or have ideas for other checks.

  • Suggest using aptos_std::math64::mul_div instead of a * b / c to prevent intermediate overflow. Same with u8 and u128 for which similar functions exist.
  • Find code patterns that look like almost swapped, and suggest using a proper swap, eg., in the following cases:
    • x = y; y = x;,
    • a.b = x.y; x.y = a.b;
  • Check known to abort (at compile time) cases:
    • left/right shift by a constant, in cases where it is known to abort
    • divide or modulo by zero
  • Identify and suggest various boolean simplifications:
    • x && true, true && x => x
    • x || false, false || x => x
    • x && false => {x; false}
    • false && x => false
    • x || true => {x; true}
    • true || x => true
  • Identify various side-effect free statements that can be removed, e.g.,
    • (&mut 0) = 3;
    • &x;
    • pure_side_effect_free_function();
  • Find cases of assert!(true) or assert!(false), and suggest they can either be removed or replaced with an explicit abort.
  • Find cases of bad bit mask (refer here for various rules: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask).
  • Find cases of ineffective bit mask (refer here for various rules: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask)
  • Find cases when same (pure) operands are used for the binary operations: ==, >, >=, <, <=, !=, &&, ||, &, |, ^, ``, /.
  • Find cases of self assignment, e.g., x.y = x.y, which can all be removed.
  • Find cases where a &mut of a const is taken: the mutable reference will refer to the copy, not the original const item (Rust also warns on this).
  • Find cases of bad min-max (see https://rust-lang.github.io/rust-clippy/master/index.html#min_max)
  • Find mistyped literal suffixes (see https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes)
  • Find needless loops: loops that always break, return, or continue. All they do is obfuscate the code, so rewrite code without loop.
  • Find needlessly complex boolean expressions that can be simplified: e.g., a && b || a can be replaced with just a.
  • Find code patterns that resemble C-style underflow/overflow checks: if (a + b < a) { ... }.
  • Find redundant comparisons that can be simplified: x <= 400 && a < 500, and always false/true comparisons: x <= 400 && x > 500.
  • Find redefinition with the same name: let a = a; This is likely unintentional.
  • Find empty ranges in for loops: 10..0, etc. This might not be intentional, the developer might be erroneously attempting a reverse range.
  • Find while loops with immutable condition: such code can likely be simplified for clarity.
  • Find cases where we use private constants in public inline functions. Currently, we only have private constants.
  • Check for empty if branch with no else branch (also, empty if with some else branch).
  • Find collapsible if conditions (i.e., nested if that can be collapsed with &&).
  • Find collapsible else { if ... } => else if ....
  • Find empty else branches, which can be dropped.
  • Find needless return at the end of a function.
  • Find unnecessary casts (x as u64 when x is already u64).
  • Check for loop {} expressions (empty loops that do not terminate).
  • Find patterns like (&mut v).foo() which can be simplified to v.foo(), because needed mutable/immutable references are automatically added in receiver-style calls.
  • Identify cases where a simpler Move 2 syntactic sugar can be used, and suggest using that instead (if the language version is >= Move 2). Eg., use receiver style syntax instead when possible, use index operations when possible.
  • Find cases where Foo {foo: foo} can be replaced by just Foo {foo} and suggest it.
@vineethk vineethk added the enhancement New feature or request label Nov 7, 2024
@vineethk vineethk added the move-linter Issues related to the Move Linter label Nov 7, 2024
@vineethk vineethk moved this from 🆕 New to For Grabs in Move Language and Runtime Nov 7, 2024
@vineethk vineethk added the stale-exempt Prevents issues from being automatically marked and closed as stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request move-linter Issues related to the Move Linter stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: For Grabs
Development

No branches or pull requests

1 participant