Skip to content

collapsible_if_else

Source Code

What it does

Checks for nested if statements inside the else statement that can be collapsed into a single if-else statement.

Example

cairo
fn main() {
    let x = true;
    if x {
        println!("x is true");
    } else {
        if !x {
            println!("x is false");
        }
    }
}

Can be refactored to:

cairo
fn main() {
    let x = true;
    if x {
        println!("x is true");
    } else if !x {
        println!("x is false");
    }
}