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

Add collapsible_match #73

Open
0xLucqs opened this issue Sep 18, 2024 · 2 comments
Open

Add collapsible_match #73

0xLucqs opened this issue Sep 18, 2024 · 2 comments

Comments

@0xLucqs
Copy link
Contributor

0xLucqs commented Sep 18, 2024

What it does

Finds nested match or if let expressions where the patterns may be “collapsed” together without adding any branches.

Note that this lint is not intended to find all cases where nested match patterns can be merged, but only cases where merging would most likely make the code more readable.

Why is this bad?

It is unnecessarily verbose and complex.

Example

fn func(opt: Option<Result<u64, felt252>>) {
    let n = match opt {
        Some(n) => match n {
            Ok(n) => n,
            _ => return,
        }
        None => return,
    };
}

Use instead:

fn func(opt: Option<Result<u64, felt252>>) {
    let n = match opt {
        Some(Ok(n)) => n,
        _ => return,
    };
}
@0xLucqs
Copy link
Contributor Author

0xLucqs commented Sep 18, 2024

@lindsaymoralesb do you want to do that one ?

@lindsaymoralesb
Copy link
Contributor

Yes! Sure @0xLucqs

@mkaput mkaput added this to cairo-lint Dec 9, 2024
@github-project-automation github-project-automation bot moved this to Triage in cairo-lint Dec 9, 2024
@mkaput mkaput moved this from Triage to Backlog in cairo-lint Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants