keep-starknet-strange / cairo-lint

A collection of lints to catch common mistakes and improve your Cairo code.
20 stars 37 forks source link

Add `equatable_if_let` #16

Closed 0xLucqs closed 1 month ago

0xLucqs commented 3 months ago

What it does

Checks for pattern matchings that can be expressed using equality.

Why is this bad?

It reads better and has less cognitive load because equality won’t cause binding. It is a Yoda condition. Yoda conditions are widely criticized for increasing the cognitive load of reading the code. Equality is a simple bool expression and can be merged with && and || and reuse if blocks

Example

if let Option::Some(2) = x {
   do_thing();
}

Use instead:

if x == Option::Some(2) {
   do_thing();
}
BernalHQ commented 3 months ago

Hi @0xLucqs, can i try this?

0xLucqs commented 2 months ago

sure can you join the telegram group as well so i can help if you're stuck or don't know how to start ? https://t.me/cairolint

BernalHQ commented 2 months ago

Thanks @0xLucqs