Skip to content

Add an analyzer for a match where an if would do - #3470

Merged
nojaf merged 1 commit into
fsprojects:mainfrom
nojaf:snob-match-analyzer
Sep 12, 2026
Merged

nojaf merged 1 commit into
fsprojects:mainfrom
nojaf:snob-match-analyzer

Conversation

@nojaf

@nojaf nojaf commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

A match is for taking a value apart. One that only asks whether a boolean is true tells the reader to expect a destructuring and then does not deliver one, so FANTOMAS-SNOBMATCH-001 asks for an if instead.

The rule is held to the boolean case, where the rewrite is mechanical: the scrutinee becomes the condition and is written once. The shape next door, a constant arm and a binder holding the scrutinee under a second name, is left alone, because every instance of it in this repository is the IndexOf idiom, where an if has to call IndexOf twice or bind it above. It also stays quiet on match!, on function, on a when guard and on a conditional directive inside the match, each because the rewrite would be more than a rewrite.

List.partitionWhile held the only instance and is now an if.

A match is for taking a value apart. One that only asks whether a boolean
is true tells the reader to expect a destructuring and then does not
deliver one, so FANTOMAS-SNOBMATCH-001 asks for an if instead.

The rule is held to the boolean case, where the rewrite is mechanical:
the scrutinee becomes the condition and is written once. The shape next
door, a constant arm and a binder holding the scrutinee under a second
name, is left alone, because every instance of it in this repository is
the IndexOf idiom, where an if has to call IndexOf twice or bind it
above. It also stays quiet on match!, on function, on a when guard and
on a conditional directive inside the match, each because the rewrite
would be more than a rewrite.

List.partitionWhile held the only instance and is now an if.
@nojaf
nojaf merged commit 9c69700 into fsprojects:main Sep 12, 2026
13 checks passed
@nojaf
nojaf deleted the snob-match-analyzer branch September 12, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant