jfmengels/elm-review-simplify
View on GitHubSimplify `if x then (_, True) else (_,False)` (and other conditionals that differ only by a boolean literal)
Open
#11 opened on Jul 17, 2021
enhancementhelp wanted
Repository metrics
- Stars
- (22 stars)
- PR merge metrics
- (PR metrics pending)
Description
Haven't put a ton of thought into how difficult it would be to implement as a rule, but I ran into it in my code today and noticed it wasn't caught by elm-review-simplify currently.
if bar then
( foo, True )
else
( foo, False )
can be simplified to just:
( foo, bar )
Honestly this could be extended to basically any two expressions that differ only by a Boolean between conditions, but it might be challenging to check for that.
E.g.
if bar then
{ a = foo, b = True }
else
{ a = foo, b = False }
if bar then
func foo True
else
func foo False
Off the top of my head, one could maybe descend into the two Node Expressions of an IfBlock and check for the presence of a boolean literal, then compare the ASTs for equality with the literal swapped?