Skip to content

Commit d0f34e0

Browse files
committed
Hints(,tests): add conditionless reduction
1 parent c621861 commit d0f34e0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/FSharpLint.Core/fsharplint.json

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

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,21 @@ let x y =
964964
this.SetConfig(["(List.singleton x) @ y ===> x :: y"])
965965
this.Parse(source)
966966
Assert.AreEqual(expected, this.ApplyQuickFix source)
967+
968+
[<Test>]
969+
member this.``Result same regardless of condition can remove conditional block``() =
970+
let source = """
971+
if (someCondition a b) then
972+
res
973+
else
974+
res
975+
"""
976+
977+
let expected = """
978+
res
979+
"""
980+
981+
this.SetConfig(["if x then y else y ===> y"])
982+
this.Parse(source)
983+
Assert.AreEqual(expected, this.ApplyQuickFix source)
984+

0 commit comments

Comments
 (0)