Skip to content

Commit 979b4cc

Browse files
authored
Merge PR #764 from webwarrior-ws/wip/failwithBadUsageBug
FailwithBadUsage: fixed case with failwithf application (false negative).
2 parents 81ccc0c + 8c60856 commit 979b4cc

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/FSharpLint.Core/Rules/Conventions/RaiseWithTooManyArguments/FailwithBadUsage.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ let private runner (args: AstNodeRuleParams) =
6767

6868
let rec checkExpr node maybeIdentifier =
6969
match node with
70+
| SynExpr.App (_, _, (SynExpr.App(_) as innerExpr), _, _) ->
71+
checkExpr innerExpr maybeIdentifier
7072
| SynExpr.App (_, _, SynExpr.Ident failwithId, expression, range) when
7173
failwithId.idText = "failwith"
7274
|| failwithId.idText = "failwithf"

tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let bar () =
3232
member this.FailwithWithBadArgumentsEmptyMessage3() =
3333
this.Parse """
3434
let foo () =
35-
failwith "foo"
35+
failwith "foo1"
3636
let bar () =
3737
failwith String.Empty
3838
"""
@@ -44,9 +44,9 @@ let bar () =
4444
member this.FailwithWithGoodArguments() =
4545
this.Parse """
4646
let foo () =
47-
failwith "foo"
47+
failwith "foo2"
4848
let bar () =
49-
failwith "bar"
49+
failwith "bar2"
5050
"""
5151

5252
this.AssertNoWarnings()
@@ -55,7 +55,7 @@ let bar () =
5555
member this.FailwithWithGoodArguments2() =
5656
this.Parse """
5757
let foo () =
58-
failwith "foo"
58+
failwith "foo3"
5959
"""
6060

6161
this.AssertNoWarnings()
@@ -79,7 +79,7 @@ try
7979
foo()
8080
with
8181
| e ->
82-
failwith "bar"
82+
failwith "bar4"
8383
"""
8484

8585
Assert.IsTrue this.ErrorsExist
@@ -92,7 +92,7 @@ try
9292
foo()
9393
with
9494
| e ->
95-
raise new Exception("bar",e)
95+
raise new Exception("bar5", e)
9696
"""
9797

9898
Assert.IsTrue this.NoErrorsExist
@@ -104,17 +104,39 @@ try
104104
foo()
105105
with
106106
| e ->
107-
failwithf "bar"
107+
failwithf "bar6"
108108
"""
109109

110110
Assert.IsTrue this.ErrorsExist
111111
Assert.IsTrue(this.ErrorExistsAt(6, 4))
112112

113113
[<Test>]
114-
member this.FailwithWithfGoodArguments2() =
114+
member this.FailwithfShouldNotSwallowExceptions2() =
115+
this.Parse """
116+
try
117+
foo()
118+
with
119+
| e ->
120+
failwithf "bar7 %i" 42
121+
"""
122+
123+
Assert.IsTrue this.ErrorsExist
124+
Assert.IsTrue(this.ErrorExistsOnLine 6)
125+
126+
[<Test>]
127+
member this.FailwithfWithGoodArguments() =
128+
this.Parse """
129+
let foo () =
130+
failwithf "foo8 %i" 42
131+
"""
132+
133+
this.AssertNoWarnings()
134+
135+
[<Test>]
136+
member this.FailwithfWithGoodArguments2() =
115137
this.Parse """
116138
let foo () =
117-
failwithf "foo"
139+
failwithf "foo9"
118140
"""
119141

120142
this.AssertNoWarnings()

0 commit comments

Comments
 (0)