Skip to content

manual_is_empty

Default: Enabled

Source Code

What it does

Checks for manual implementation of is_empty method in match and if expressions.

Example

cairo
fn main() {
    let ary: Array<u32> = array![1, 2, 3];
    let _a = match ary {
        ArrayTrait::new() => true, // or array![], or Default::default(), or ArrayDefault::default()
        _ => false,
    };
    let _b = if ary == array![] { // or ArrayTrait::new(), or `if ary.len() == 0`
        // do stuff...
    } else {
        // do other stuff...
    }
}

Can be replaced with:

cairo
fn main() {
    let res_val: Result<i32> = Result::Err('err');
    let _a = res_val.is_empty();
    let _b = if ary.is_empty() {
        // do stuff...
    } else {
        // do other stuff...
    }
}