Skip to content

Commit 706338a

Browse files
committed
Update scalafmt
1 parent 24a3b54 commit 706338a

File tree

7 files changed

+88
-77
lines changed

7 files changed

+88
-77
lines changed

.scalafmt.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
version = 2.7.5
1+
runner.dialect = scala3
2+
version = 3.0.0
23
maxColumn = 120

core/src/main/scala/sttp/capabilities/package.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ package sttp
33
package object capabilities {
44

55
/** A capability of sending and receiving streaming bodies.
6-
* @tparam S The type to use as a capability. Should be the self-type of the implementation. This is needed so that
7-
* capabilities are expressed in terms of class types, not singleton object types.
6+
* @tparam S
7+
* The type to use as a capability. Should be the self-type of the implementation. This is needed so that
8+
* capabilities are expressed in terms of class types, not singleton object types.
89
*/
910
class Streams[S] {
1011
type BinaryStream
1112
type Pipe[_, _]
1213
}
1314

14-
/** A capability of supporting the given effect type, such as [[scala.concurrent.Future]].
15-
* Used only as a type parameter, without implementations.
15+
/** A capability of supporting the given effect type, such as [[scala.concurrent.Future]]. Used only as a type
16+
* parameter, without implementations.
1617
*/
1718
trait Effect[F[_]]
1819

19-
/** A capability of sending websocket requests.
20-
* Used only as a type parameter, without implementations.
20+
/** A capability of sending websocket requests. Used only as a type parameter, without implementations.
2121
*/
2222
trait WebSockets
2323
}

core/src/main/scala/sttp/monad/MonadError.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ package sttp.monad
33
import scala.concurrent.{ExecutionContext, Future, Promise}
44
import scala.util.{Failure, Success, Try}
55

6-
/** A basic monad interface, allowing abstract manipulation of effectful values, represented using the type
7-
* constructor `F`.
6+
/** A basic monad interface, allowing abstract manipulation of effectful values, represented using the type constructor
7+
* `F`.
88
*
9-
* A computation yielding results of type `T` is represented as a value of type `F[T]`. Such values:
10-
* * can be transformed using `map`
11-
* * can be run in sequence using `flatMap`
12-
* * errors can be handled using `handleError`
13-
* * and new computations can be created using `unit`, `eval` and `suspend`
9+
* A computation yielding results of type `T` is represented as a value of type `F[T]`. Such values: * can be
10+
* transformed using `map` * can be run in sequence using `flatMap` * errors can be handled using `handleError` * and
11+
* new computations can be created using `unit`, `eval` and `suspend`
1412
*
15-
* To use convenient `.map`, `.flatMap` syntax, make sure an implicit instance of `MonadError` is in scope, and
16-
* import: `import sttp.monad.syntax._`. This adds the appropriate extension methods.
13+
* To use convenient `.map`, `.flatMap` syntax, make sure an implicit instance of `MonadError` is in scope, and import:
14+
* `import sttp.monad.syntax._`. This adds the appropriate extension methods.
1715
*/
1816
trait MonadError[F[_]] {
1917
def unit[T](t: T): F[T]

ws/src/main/scala/sttp/ws/WebSocket.scala

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import sttp.monad.syntax._
66

77
/** Effectful interactions with a web socket. Interactions can happen:
88
*
9-
* - on the frame level, by sending and receiving raw [[WebSocketFrame]]s
10-
* - using the provided `receive*` methods to obtain concatenated data frames, or string/byte payloads, and the
11-
* `send*` method to send string/binary frames.
9+
* - on the frame level, by sending and receiving raw [[WebSocketFrame]] s
10+
* - using the provided `receive*` methods to obtain concatenated data frames, or string/byte payloads, and the
11+
* `send*` method to send string/binary frames.
1212
*
1313
* The `send*` and `receive*` methods may result in a failed effect, with either one of [[WebSocketException]]
14-
* exceptions, or a backend-specific exception. Specifically, they will fail with [[WebSocketClosed]] if the
15-
* web socket is closed.
14+
* exceptions, or a backend-specific exception. Specifically, they will fail with [[WebSocketClosed]] if the web socket
15+
* is closed.
1616
*
1717
* See the `either` and `eitherClose` method to lift web socket closed events to the value level.
1818
*/
@@ -23,8 +23,8 @@ trait WebSocket[F[_]] {
2323
* happen.
2424
*
2525
* However, not all implementations expose the close frame, and web sockets might also get closed without the proper
26-
* close frame exchange. In such cases, as well as when invoking `receive`/`send` after receiving a close frame,
27-
* this effect will fail with the [[WebSocketClosed]] exception.
26+
* close frame exchange. In such cases, as well as when invoking `receive`/`send` after receiving a close frame, this
27+
* effect will fail with the [[WebSocketClosed]] exception.
2828
*
2929
* *Should be only called sequentially!* (from a single thread/fiber). Because web socket frames might be fragmented,
3030
* calling this method concurrently might result in threads/fibers receiving fragments of the same frame.
@@ -38,12 +38,13 @@ trait WebSocket[F[_]] {
3838
def send(f: WebSocketFrame, isContinuation: Boolean = false): F[Unit]
3939
def isOpen(): F[Boolean]
4040

41-
/** Receive a single data frame, ignoring others. The frame might be a fragment.
42-
* Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
41+
/** Receive a single data frame, ignoring others. The frame might be a fragment. Will fail with [[WebSocketClosed]] if
42+
* the web socket is closed, or if a close frame is received.
4343
*
4444
* *Should be only called sequentially!* (from a single thread/fiber).
4545
*
46-
* @param pongOnPing Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
46+
* @param pongOnPing
47+
* Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
4748
*/
4849
def receiveDataFrame(pongOnPing: Boolean = true): F[WebSocketFrame.Data[_]] =
4950
receive().flatMap {
@@ -54,62 +55,66 @@ trait WebSocket[F[_]] {
5455
case _ => receiveDataFrame(pongOnPing)
5556
}
5657

57-
/** Receive a single text data frame, ignoring others. The frame might be a fragment. To receive whole messages,
58-
* use [[receiveText]].
59-
* Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
58+
/** Receive a single text data frame, ignoring others. The frame might be a fragment. To receive whole messages, use
59+
* [[receiveText]]. Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
6060
*
6161
* *Should be only called sequentially!* (from a single thread/fiber).
6262
*
63-
* @param pongOnPing Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
63+
* @param pongOnPing
64+
* Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
6465
*/
6566
def receiveTextFrame(pongOnPing: Boolean = true): F[WebSocketFrame.Text] =
6667
receiveDataFrame(pongOnPing).flatMap {
6768
case t: WebSocketFrame.Text => t.unit
6869
case _ => receiveTextFrame(pongOnPing)
6970
}
7071

71-
/** Receive a single binary data frame, ignoring others. The frame might be a fragment. To receive whole messages,
72-
* use [[receiveBinary]].
73-
* Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
72+
/** Receive a single binary data frame, ignoring others. The frame might be a fragment. To receive whole messages, use
73+
* [[receiveBinary]]. Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is
74+
* received.
7475
*
7576
* *Should be only called sequentially!* (from a single thread/fiber).
7677
*
77-
* @param pongOnPing Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
78+
* @param pongOnPing
79+
* Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
7880
*/
7981
def receiveBinaryFrame(pongOnPing: Boolean = true): F[WebSocketFrame.Binary] =
8082
receiveDataFrame(pongOnPing).flatMap {
8183
case t: WebSocketFrame.Binary => t.unit
8284
case _ => receiveBinaryFrame(pongOnPing)
8385
}
8486

85-
/** Receive a single text message (which might come from multiple, fragmented frames).
86-
* Ignores non-text frames and returns combined results.
87-
* Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
87+
/** Receive a single text message (which might come from multiple, fragmented frames). Ignores non-text frames and
88+
* returns combined results. Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is
89+
* received.
8890
*
8991
* *Should be only called sequentially!* (from a single thread/fiber).
9092
*
91-
* @param pongOnPing Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
93+
* @param pongOnPing
94+
* Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
9295
*/
9396
def receiveText(pongOnPing: Boolean = true): F[String] =
9497
receiveConcat(() => receiveTextFrame(pongOnPing), _ + _)
9598

96-
/** Receive a single binary message (which might come from multiple, fragmented frames).
97-
* Ignores non-binary frames and returns combined results.
98-
* Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is received.
99+
/** Receive a single binary message (which might come from multiple, fragmented frames). Ignores non-binary frames and
100+
* returns combined results. Will fail with [[WebSocketClosed]] if the web socket is closed, or if a close frame is
101+
* received.
99102
*
100103
* *Should be only called sequentially!* (from a single thread/fiber).
101104
*
102-
* @param pongOnPing Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
105+
* @param pongOnPing
106+
* Should a [[WebSocketFrame.Pong]] be sent when a [[WebSocketFrame.Ping]] is received.
103107
*/
104108
def receiveBinary(pongOnPing: Boolean): F[Array[Byte]] =
105109
receiveConcat(() => receiveBinaryFrame(pongOnPing), _ ++ _)
106110

107-
/** Extracts the received close frame (if available) as the left side of an either, or returns the original result
108-
* on the right.
111+
/** Extracts the received close frame (if available) as the left side of an either, or returns the original result on
112+
* the right.
109113
*
110114
* Will fail with [[WebSocketClosed]] if the web socket is closed, but no close frame is available.
111115
*
112-
* @param f The effect describing web socket interactions.
116+
* @param f
117+
* The effect describing web socket interactions.
113118
*/
114119
def eitherClose[T](f: => F[T]): F[Either[WebSocketFrame.Close, T]] =
115120
f.map(t => Right(t): Either[WebSocketFrame.Close, T]).handleError { case WebSocketClosed(Some(close)) =>
@@ -118,12 +123,13 @@ trait WebSocket[F[_]] {
118123

119124
/** Returns an effect computing a:
120125
*
121-
* - `Left` if the web socket is closed - optionally with the received close frame (if available).
122-
* - `Right` with the original result otherwise.
126+
* - `Left` if the web socket is closed - optionally with the received close frame (if available).
127+
* - `Right` with the original result otherwise.
123128
*
124129
* Will never fail with a [[WebSocketClosed]].
125130
*
126-
* @param f The effect describing web socket interactions.
131+
* @param f
132+
* The effect describing web socket interactions.
127133
*/
128134
def either[T](f: => F[T]): F[Either[Option[WebSocketFrame.Close], T]] =
129135
f.map(t => Right(t): Either[Option[WebSocketFrame.Close], T]).handleError { case WebSocketClosed(close) =>

ws/src/main/scala/sttp/ws/WebSocketException.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package sttp.ws
22

33
abstract class WebSocketException(msg: String) extends Exception(msg)
44

5-
/** @param frame The received closing frame, if available.
5+
/** @param frame
6+
* The received closing frame, if available.
67
*/
78
case class WebSocketClosed(frame: Option[WebSocketFrame.Close]) extends WebSocketException(null)
89

ws/src/main/scala/sttp/ws/WebSocketFrame.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ object WebSocketFrame {
1313

1414
/** A text frame with fragmentation or extension bits.
1515
*
16-
* @param payload a text fragment.
17-
* @param finalFragment flag indicating whether or not this is the final fragment
18-
* @param rsv optional extension bits
16+
* @param payload
17+
* a text fragment.
18+
* @param finalFragment
19+
* flag indicating whether or not this is the final fragment
20+
* @param rsv
21+
* optional extension bits
1922
*/
2023
case class Text(payload: String, finalFragment: Boolean, rsv: Option[Int]) extends Data[String]
2124

2225
/** A binary frame with fragmentation or extension bits.
2326
*
24-
* @param payload a binary payload
25-
* @param finalFragment flag indicating whether or not this is the last fragment
26-
* @param rsv optional extension bits
27+
* @param payload
28+
* a binary payload
29+
* @param finalFragment
30+
* flag indicating whether or not this is the last fragment
31+
* @param rsv
32+
* optional extension bits
2733
*/
2834
case class Binary(payload: Array[Byte], finalFragment: Boolean, rsv: Option[Int]) extends Data[Array[Byte]]
2935

ws/src/main/scala/sttp/ws/testing/WebSocketStub.scala

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import sttp.ws.{WebSocket, WebSocketClosed, WebSocketFrame}
66

77
import scala.util.{Failure, Success, Try}
88

9-
/** A stub for websockets that uses a queue of frames which are returned when the client calls
10-
* [[WebSocket.receive]].
9+
/** A stub for websockets that uses a queue of frames which are returned when the client calls [[WebSocket.receive]].
1110
*
12-
* New messages can be added to queue in reaction to [[WebSocket.send]] being invoked, by specifying the
13-
* behavior using one of the [[thenRespond]] variants.
11+
* New messages can be added to queue in reaction to [[WebSocket.send]] being invoked, by specifying the behavior using
12+
* one of the [[thenRespond]] variants.
1413
*
1514
* For more complex cases, please provide your own implementation of [[WebSocket]].
1615
*/
@@ -41,11 +40,11 @@ class WebSocketStub[S](
4140
(_, frame) => ((), addReceived(frame))
4241
)
4342

44-
/** Creates a stub that has the same initial responses, but replaces the function that adds responses to be
45-
* received in reaction to [[WebSocket.send]] being invoked.
43+
/** Creates a stub that has the same initial responses, but replaces the function that adds responses to be received
44+
* in reaction to [[WebSocket.send]] being invoked.
4645
*
47-
* More powerful version of [[thenRespond()]], as the given function can additionally use state and implement stateful
48-
* logic for computing response messages.
46+
* More powerful version of [[thenRespond()]], as the given function can additionally use state and implement
47+
* stateful logic for computing response messages.
4948
*/
5049
def thenRespondS[S2](initial: S2)(
5150
onSend: (S2, WebSocketFrame) => (S2, List[WebSocketFrame])
@@ -55,13 +54,13 @@ class WebSocketStub[S](
5554
(s2, lf.map(Try(_)))
5655
}
5756

58-
/** Creates a stub that has the same initial responses, but replaces the function that adds responses to be
59-
* received in reaction to [[WebSocket.send]] being invoked.
57+
/** Creates a stub that has the same initial responses, but replaces the function that adds responses to be received
58+
* in reaction to [[WebSocket.send]] being invoked.
6059
*
6160
* More powerful version of:
62-
* - [[thenRespond()]], as the given function can additionally use state and implement stateful
63-
* logic for computing response messages.
64-
* - [[thenRespondS()]] which allows receiving to fail with an exception.
61+
* - [[thenRespond()]], as the given function can additionally use state and implement stateful logic for computing
62+
* response messages.
63+
* - [[thenRespondS()]] which allows receiving to fail with an exception.
6564
*/
6665
def thenRespondWithS[S2](initial: S2)(
6766
onSend: (S2, WebSocketFrame) => (S2, List[Try[WebSocketFrame]])
@@ -121,29 +120,29 @@ class WebSocketStub[S](
121120

122121
object WebSocketStub {
123122

124-
/** Creates a stub which will return the given responses when [[WebSocket.receive]] is called by the client.
125-
* More messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently
126-
* calling one of the [[WebSocketStub.thenRespond]] methods.
123+
/** Creates a stub which will return the given responses when [[WebSocket.receive]] is called by the client. More
124+
* messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently calling one
125+
* of the [[WebSocketStub.thenRespond]] methods.
127126
*/
128127
def initialReceiveWith(
129128
events: List[Try[WebSocketFrame]]
130129
): WebSocketStub[Unit] = {
131130
new WebSocketStub(events, (), (_, _) => ((), List.empty))
132131
}
133132

134-
/** Creates a stub which will return the given messages when [[WebSocket.receive]] is called by the client.
135-
* More messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently
136-
* calling one of the [[WebSocketStub.thenRespond]] methods.
133+
/** Creates a stub which will return the given messages when [[WebSocket.receive]] is called by the client. More
134+
* messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently calling one
135+
* of the [[WebSocketStub.thenRespond]] methods.
137136
*/
138137
def initialReceive(
139138
messages: List[WebSocketFrame]
140139
): WebSocketStub[Unit] = {
141140
initialReceiveWith(messages.map(m => Success(m)))
142141
}
143142

144-
/** Creates a stub which won't return any initial frames when [[WebSocket.receive]] is called by the client.
145-
* More messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently
146-
* calling one of the [[WebSocketStub.thenRespond]] methods.
143+
/** Creates a stub which won't return any initial frames when [[WebSocket.receive]] is called by the client. More
144+
* messages can be enqueued to be returned by the stub in response to [[WebSocket.send]] by subsequently calling one
145+
* of the [[WebSocketStub.thenRespond]] methods.
147146
*/
148147
def noInitialReceive: WebSocketStub[Unit] = initialReceiveWith(List.empty)
149148
}

0 commit comments

Comments
 (0)