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

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

Open
knocte opened this issue May 2, 2022 · 1 comment · May be fixed by #588
Open

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

knocte opened this issue May 2, 2022 · 1 comment · May be fixed by #588

Comments

@knocte
Copy link
Collaborator

knocte commented May 2, 2022

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).

janus added a commit to janus/FSharpLint that referenced this issue May 2, 2022
janus added a commit to janus/FSharpLint that referenced this issue May 3, 2022
janus added a commit to janus/FSharpLint that referenced this issue May 3, 2022
parhamsaremi pushed a commit to parhamsaremi/FSharpLint that referenced this issue Nov 21, 2022
@Thorium
Copy link
Member

Thorium commented Nov 18, 2023

I think match is very readable if you have used to it.
How would you made this more readable by if clause?

match a when
| Some x when x > 21 -> x
| _ -> 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants