Skip to content

Commit

Permalink
Update style of SynExpr.TryWith with a single clause. Fixes fsproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 19, 2022
1 parent 8cd235d commit a03b170
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ let topLevelFunction () =
printfn "Something to print"
try
nothing ()
with
| ex -> splash ()
with ex ->
splash ()
()
"""

Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/ColMultilineItemTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ let b (x: int) (y: int) : int =
let c () =
try
0
with
| ex -> 1
with ex ->
1
"""

[<Test>]
Expand Down
18 changes: 9 additions & 9 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,10 +1724,10 @@ try
try
()
// xxx
with
| _ -> ()
with
| _ -> ()
with _ ->
()
with _ ->
()
"""

[<Test>]
Expand All @@ -1754,7 +1754,8 @@ try
with


| b -> c
| b ->
c
"""

[<Test>]
Expand All @@ -1778,13 +1779,12 @@ with
"""
try
a
with
| b ->
with b ->
try
c
// inner comment
with
| d -> ()
with d ->
()
"""

[<Test>]
Expand Down
18 changes: 8 additions & 10 deletions src/Fantomas.Core.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,7 @@ let start (args: IArgs) =
.Run()
0
with
| ex ->
with ex ->
Log.Fatal(ex, "Host terminated unexpectedly")
1
finally
Expand Down Expand Up @@ -1317,8 +1316,8 @@ try
#if DEF
()
#endif
with
| _ -> ()
with _ ->
()
"""

[<Test>]
Expand Down Expand Up @@ -2350,8 +2349,7 @@ module ReactHookExtensions =
do setDeferred (Deferred<'T>.InProgress)
let! output = operation
do setDeferred (Deferred<'T>.Resolved output)
with
| error ->
with error ->
#if DEBUG
Browser.Dom.console.log (error)
#endif
Expand Down Expand Up @@ -2742,10 +2740,10 @@ try
#if FOO
()
#endif
with
| _ -> ()
with
| _ -> ()
with _ ->
()
with _ ->
()
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Core.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,8 +1759,7 @@ let sendPushNotifications =
let ps = PushSubscription(s.Endpoint, s.P256DH, s.Auth)
do! webPushClient.SendNotificationAsync(ps, payload, vapidDetails)
with
| :? WebPushException as wpex ->
with :? WebPushException as wpex ->
log.LogError(sprintf "Couldn't send notification to %s, %A" user.UserId wpex)
do!
Expand Down
67 changes: 53 additions & 14 deletions src/Fantomas.Core.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ let result1 = divide1 100 0
let divide1 x y =
try
Some(x / y)
with
| :? System.DivideByZeroException ->
with :? System.DivideByZeroException ->
printfn "Division by zero!"
None
Expand Down Expand Up @@ -279,8 +278,8 @@ let x =
if
try
true
with
| Failure _ -> false
with Failure _ ->
false
then
()
else
Expand Down Expand Up @@ -819,7 +818,8 @@ try
foo.CreationTime <> defaultTime
with
// hmm
| :? FileNotFoundException -> false
| :? FileNotFoundException ->
false
"""

[<Test>]
Expand Down Expand Up @@ -847,7 +847,8 @@ try
foo.CreationTime <> defaultTime
with
// hmm
| :? FileNotFoundException -> false
| :? FileNotFoundException ->
false
"""

[<Test>]
Expand Down Expand Up @@ -881,7 +882,8 @@ module Foo =
failwith ""
with
// hi!
| :? Exception as e -> failwith ""
| :? Exception as e ->
failwith ""
"""

[<Test>]
Expand Down Expand Up @@ -914,7 +916,8 @@ module Foo =
failwith ""
with
// hi!
| :? Exception as e -> failwith ""
| :? Exception as e ->
failwith ""
"""

[<Test>]
Expand Down Expand Up @@ -980,7 +983,8 @@ module Foo =
foo.CreationTime <> defaultTime
with
// hmm
| :? FileNotFoundException -> false
| :? FileNotFoundException ->
false
exists
Expand All @@ -989,7 +993,7 @@ module Foo =
"""

[<Test>]
let ``short catch clause in try/with should have pipe, 1571`` () =
let ``short catch clause in try/with should not have pipe, 1571`` () =
formatSourceString
false
"""
Expand All @@ -1006,8 +1010,8 @@ with
"""
try
()
with
| exc -> ()
with exc ->
()
"""

[<Test>]
Expand Down Expand Up @@ -1035,8 +1039,43 @@ let isAbstractNonVirtualMember (m: FSharpMemberOrFunctionOrValue) =
&& (try
m.ImplementedAbstractSignatures <> null
&& m.ImplementedAbstractSignatures.Count = 0
with
| _ -> true) // exceptions here trying to acces the member means we're safe
with _ ->
true) // exceptions here trying to acces the member means we're safe
// this member is not an override
&& not m.IsOverrideOrExplicitInterfaceImplementation
"""

[<Test>]
let ``try/with with a single clause, 1881`` () =
formatSourceString
false
"""
// OK
try
persistState currentState
with ex ->
printfn "Something went wrong: %A" ex
// OK
try
persistState currentState
with :? System.ApplicationException as ex ->
printfn "Something went wrong: %A" ex
"""
config
|> prepend newline
|> should
equal
"""
// OK
try
persistState currentState
with ex ->
printfn "Something went wrong: %A" ex
// OK
try
persistState currentState
with :? System.ApplicationException as ex ->
printfn "Something went wrong: %A" ex
"""
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ type Foobar =
.GetSystemAssemblies()
.Contains(fileNameWithoutExtension filename))
|| tcConfig.FxResolver.IsInReferenceAssemblyPackDirectory filename)
with
| _ -> false
with _ ->
false
"""

[<Test>]
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/IfThenElseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,8 @@ let main argv =
new StreamWriter(outFile)
buffer.Flush()
with
| exn -> eprintfn "The following exception occurred while formatting %s: %O" inFile exn
with exn ->
eprintfn "The following exception occurred while formatting %s: %O" inFile exn
0
"""
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/InterpolatedStringTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ $"
let b = y
let c = 9
foo ()
with
| ex -> interpolationFailed ()}
with ex ->
interpolationFailed ()}
"
"""

Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ type Foo() =
try
try
cleanUp ()
with
| :? IOException -> foo ()
with
| exc -> foooo ()
with :? IOException ->
foo ()
with exc ->
foooo ()
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Core.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,7 @@ let private authenticateRequest (logger: ILogger) header =
logger.LogError(sprintf "User has a valid token but lacks the correct permission")
return None
}
with
| exn ->
with exn ->
logger.LogError(sprintf "Could not authenticate token %s\n%A" token exn)
task { return None }
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ module ElectrumClient =
stratumClient.ServerVersion
CLIENT_NAME_SENT_TO_STRATUM_SERVER_WHEN_HELLO
PROTOCOL_VERSION_SUPPORTED
with
| :? ElectrumServerReturningErrorException as except when
except.Message.EndsWith
(PROTOCOL_VERSION_SUPPORTED.ToString())
->
with :? ElectrumServerReturningErrorException as except when
except.Message.EndsWith(
PROTOCOL_VERSION_SUPPORTED.ToString()
) ->
failwith "xxx"
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ try
item.MethodInfo.Method.Invoke(null, ipa)
|> (fun x -> x?Invoke (true))
|> fun (t: Task) -> t.Wait()
with
| _ -> ()
with _ ->
()
"""

[<Test>]
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Core.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ try
s' = s0 && can (type_match ty ty0) [])
(!the_interface)
)
with
| Failure _ -> s0
with Failure _ ->
s0
"""

[<Test>]
Expand Down Expand Up @@ -1263,8 +1263,8 @@ let private formatResponse<'options> () =
return sendBadRequest content
with
| exn -> return sendBadRequest (sprintf "%A" exn)
with exn ->
return sendBadRequest (sprintf "%A" exn)
| Error err -> return sendInternalError (err)
}
"""
Expand Down Expand Up @@ -1851,8 +1851,8 @@ match x with
| _ ->
try
somethingElse ()
with
| e -> printfn "failure %A" e)
with e ->
printfn "failure %A" e)
--*-- bar
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ fn
b
(try
somethingDangerous
with
| ex -> printfn "meh")
with ex ->
printfn "meh")
c [
a1 // hey
a2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ fn
b
(try
somethingDangerous
with
| ex -> printfn "meh")
with ex ->
printfn "meh")
c
[
b1 // comment
Expand Down
Loading

0 comments on commit a03b170

Please sign in to comment.