Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ let private runner (args: AstNodeRuleParams) =

let rec checkExpr node maybeIdentifier =
match node with
| SynExpr.App (_, _, (SynExpr.App(_) as innerExpr), _, _) ->
checkExpr innerExpr maybeIdentifier
| SynExpr.App (_, _, SynExpr.Ident failwithId, expression, range) when
failwithId.idText = "failwith"
|| failwithId.idText = "failwithf"
Expand Down
40 changes: 31 additions & 9 deletions tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let bar () =
member this.FailwithWithBadArgumentsEmptyMessage3() =
this.Parse """
let foo () =
failwith "foo"
failwith "foo1"
let bar () =
failwith String.Empty
"""
Expand All @@ -44,9 +44,9 @@ let bar () =
member this.FailwithWithGoodArguments() =
this.Parse """
let foo () =
failwith "foo"
failwith "foo2"
let bar () =
failwith "bar"
failwith "bar2"
"""

this.AssertNoWarnings()
Expand All @@ -55,7 +55,7 @@ let bar () =
member this.FailwithWithGoodArguments2() =
this.Parse """
let foo () =
failwith "foo"
failwith "foo3"
"""

this.AssertNoWarnings()
Expand All @@ -79,7 +79,7 @@ try
foo()
with
| e ->
failwith "bar"
failwith "bar4"
"""

Assert.IsTrue this.ErrorsExist
Expand All @@ -92,7 +92,7 @@ try
foo()
with
| e ->
raise new Exception("bar",e)
raise new Exception("bar5", e)
"""

Assert.IsTrue this.NoErrorsExist
Expand All @@ -104,17 +104,39 @@ try
foo()
with
| e ->
failwithf "bar"
failwithf "bar6"
"""

Assert.IsTrue this.ErrorsExist
Assert.IsTrue(this.ErrorExistsAt(6, 4))

[<Test>]
member this.FailwithWithfGoodArguments2() =
member this.FailwithfShouldNotSwallowExceptions2() =
this.Parse """
try
foo()
with
| e ->
failwithf "bar7 %i" 42
"""

Assert.IsTrue this.ErrorsExist
Assert.IsTrue(this.ErrorExistsOnLine 6)

[<Test>]
member this.FailwithfWithGoodArguments() =
this.Parse """
let foo () =
failwithf "foo8 %i" 42
"""

this.AssertNoWarnings()

[<Test>]
member this.FailwithfWithGoodArguments2() =
this.Parse """
let foo () =
failwithf "foo"
failwithf "foo9"
"""

this.AssertNoWarnings()
Expand Down
Loading