Skip to content

Rule to recommend if-else construct instead of match clause #545

@knocte

Description

@knocte

Description

If a match clause only has 2 cases, and the last case is _, then the whole thing can be converted into a simple if-then-else block, which is more readable.

Test1:

match foo with
| bar -> ()
| _ -> ()

Should throw warnings.

Test2:

match foo with
| bar -> ()
| baz -> ()
| _ -> ()

Should not throw warnings (because it has 3 cases, not 2).

Test3:

match foo with
| bar -> ()
| baz -> ()

Should not throw warnings (because its last case is not _).

Test4:

match foo with
| Bar baz -> ()
| _ -> ()

Should not throw warnings (because its first case is not a single element, so the casting is useful).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions