Skip to content

Commit 29c7f94

Browse files
committed
Hints(,tests): add conditionless reduction
1 parent 9bec3ed commit 29c7f94

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/FSharpLint.Core/fsharplint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@
410410
"false <> a ===> a",
411411
"if a then true else false ===> a",
412412
"if a then false else true ===> not a",
413+
"if x then y else y ===> y",
413414
"not (not x) ===> x",
414415

415416
"(fst x, snd x) ===> x",

tests/FSharpLint.Core.Tests/Rules/Hints/HintMatcher.fs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,21 @@ let x y =
953953

954954
this.SetConfig(["List.map f (List.map g x) ===> List.map (g >> f) x"])
955955
this.Parse(source)
956-
Assert.AreEqual(expected, this.ApplyQuickFix source)
956+
Assert.AreEqual(expected, this.ApplyQuickFix source)
957+
958+
[<Test>]
959+
member this.``Result same regardless of condition can remove conditional block``() =
960+
let source = """
961+
if (someCondition a b) then
962+
res
963+
else
964+
res
965+
"""
966+
967+
let expected = """
968+
res
969+
"""
970+
971+
this.SetConfig(["if x then y else y ===> y"])
972+
this.Parse(source)
973+
Assert.AreEqual(expected, this.ApplyQuickFix source)

0 commit comments

Comments
 (0)