diff --git a/src/FSharpLint.Core/Rules/Conventions/RaiseWithTooManyArguments/FailwithBadUsage.fs b/src/FSharpLint.Core/Rules/Conventions/RaiseWithTooManyArguments/FailwithBadUsage.fs index 619a6cd4a..1ac1b8063 100644 --- a/src/FSharpLint.Core/Rules/Conventions/RaiseWithTooManyArguments/FailwithBadUsage.fs +++ b/src/FSharpLint.Core/Rules/Conventions/RaiseWithTooManyArguments/FailwithBadUsage.fs @@ -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" diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs index 511c7d7e8..fdec0ba3a 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/FailwithBadUsage.fs @@ -32,7 +32,7 @@ let bar () = member this.FailwithWithBadArgumentsEmptyMessage3() = this.Parse """ let foo () = - failwith "foo" + failwith "foo1" let bar () = failwith String.Empty """ @@ -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() @@ -55,7 +55,7 @@ let bar () = member this.FailwithWithGoodArguments2() = this.Parse """ let foo () = - failwith "foo" + failwith "foo3" """ this.AssertNoWarnings() @@ -79,7 +79,7 @@ try foo() with | e -> - failwith "bar" + failwith "bar4" """ Assert.IsTrue this.ErrorsExist @@ -92,7 +92,7 @@ try foo() with | e -> - raise new Exception("bar",e) + raise new Exception("bar5", e) """ Assert.IsTrue this.NoErrorsExist @@ -104,17 +104,39 @@ try foo() with | e -> - failwithf "bar" + failwithf "bar6" """ Assert.IsTrue this.ErrorsExist Assert.IsTrue(this.ErrorExistsAt(6, 4)) [] - 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) + + [] + member this.FailwithfWithGoodArguments() = + this.Parse """ +let foo () = + failwithf "foo8 %i" 42 +""" + + this.AssertNoWarnings() + + [] + member this.FailwithfWithGoodArguments2() = this.Parse """ let foo () = - failwithf "foo" + failwithf "foo9" """ this.AssertNoWarnings()