Skip to content

Commit dbec3e2

Browse files
authored
lint: Introduce scalafix Disable rules for partial (non-total) functions (#137)
* lint: Introduce scalafix Disable rules for partial (non-total) functions I took inspiration from the [Scalazzi project](https://github.com/scalaz/scalazzi/blob/master/scalafix.conf) * more non-total and side-effectful methods
1 parent 68fc398 commit dbec3e2

File tree

3 files changed

+96
-19
lines changed

3 files changed

+96
-19
lines changed

.scalafix.conf

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,77 @@ Disable.ifSynthetic = [
8080
}
8181
]
8282

83+
Disable.unlessInside = [
84+
{
85+
safeBlocks = [
86+
"cats/effect/IO"
87+
"cats/effect/Sync.delay"
88+
"monix/eval/Task"
89+
"cats/ApplicativeError.handleError"
90+
"cats/ApplicativeError.raiseError"
91+
"cats/syntax/ApplicativeErrorOps.handleError"
92+
"cats/syntax/ApplicativeErrorOps.recover"
93+
"zio/IO"
94+
"zio/Task"
95+
"zio/ZIO"
96+
"zio/ZIO_E_Throwable.effect"
97+
"zio/ZIOFunctions.effectAsync"
98+
"zio/ZIOFunctions.effectTotal"
99+
"zio/ZIOFunctions.effectTotalWith"
100+
"zio/ZIOFunctions.fail"
101+
"zio/ZIOFunctions.halt"
102+
]
103+
symbols = [
104+
{
105+
# If something is referentially transparent but not total, instead of
106+
# adding to this excludes list, add it to the includes list of the
107+
# cats.syntax.EitherObjectOps.catchNonFatal safeBlock.
108+
regex = {
109+
includes = [
110+
"^\\Qjava/net/InetAddress#getByAddress().\\E$"
111+
"^\\Qjava/net/InetAddress#getByName(\\E.*$"
112+
"^\\Qjava/net/InetSocketAddress#<init>().\\E$"
113+
"^\\Qjava/net/InetSocketAddress#<init>(+2).\\E$"
114+
]
115+
excludes = [
116+
]
117+
}
118+
message = "Method is sideeffectful, must be called from Task/IO/ZIO"
119+
}
120+
]
121+
}
122+
{
123+
safeBlocks = [
124+
"cats/syntax/EitherObjectOps.catchNonFatal"
125+
"cats/data/Validated.catchNonFatal"
126+
"cats/ApplicativeError.catchNonFatal"
127+
"cats/effect/IO"
128+
"cats/effect/Sync.delay"
129+
"monix/eval/Task"
130+
"zio/IO"
131+
"zio/Task"
132+
"zio/ZIO"
133+
"zio/ZIO_E_Throwable.effect"
134+
]
135+
symbols = [
136+
{
137+
regex = {
138+
includes = [
139+
"^\\Qjava/net/URLEncoder#\\E.*$"
140+
"^\\Qjava/net/URLDecoder#\\E.*$"
141+
"^\\Qjava/net/InetAddress#getByAddress(+1).\\E$"
142+
"^\\Qjava/net/InetSocketAddress#<init>(+1).\\E$"
143+
"^\\Qjava/net/InetSocketAddress#createUnresolved().\\E$"
144+
]
145+
excludes = [
146+
]
147+
}
148+
message = "Deterministic method is not total, must be called via Either.catchNonFatal, etc."
149+
}
150+
]
151+
}
152+
]
153+
83154
DisableSyntax {
84155
noAsInstanceOf = true
85156
noFinalize = true

http4s-server-blaze/src/main/scala/com/avast/sst/http4s/server/Http4sBlazeServerModule.scala

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,29 @@ object Http4sBlazeServerModule {
2020
def make[F[_]: ConcurrentEffect: Timer](config: Http4sBlazeServerConfig,
2121
httpApp: HttpApp[F],
2222
executionContext: ExecutionContext): Resource[F, Server[F]] = {
23-
BlazeServerBuilder[F]
24-
.bindSocketAddress(InetSocketAddress.createUnresolved(config.listenAddress, config.listenPort))
25-
.withHttpApp(httpApp)
26-
.withExecutionContext(executionContext)
27-
.withoutBanner
28-
.withNio2(config.nio2Enabled)
29-
.withWebSockets(config.webSocketsEnabled)
30-
.enableHttp2(config.http2Enabled)
31-
.withResponseHeaderTimeout(Duration.fromNanos(config.responseHeaderTimeout.toNanos))
32-
.withIdleTimeout(Duration.fromNanos(config.idleTimeout.toNanos))
33-
.withBufferSize(config.bufferSize)
34-
.withMaxRequestLineLength(config.maxRequestLineLength)
35-
.withMaxHeadersLength(config.maxHeadersLength)
36-
.withChunkBufferMaxSize(config.chunkBufferMaxSize)
37-
.withConnectorPoolSize(config.connectorPoolSize)
38-
.withChannelOption[java.lang.Boolean](StandardSocketOptions.TCP_NODELAY, config.socketOptions.tcpNoDelay)
39-
.resource
23+
for {
24+
inetSocketAddress <- Resource.liftF(
25+
ConcurrentEffect[F].delay(
26+
InetSocketAddress.createUnresolved(config.listenAddress, config.listenPort)
27+
)
28+
)
29+
server <- BlazeServerBuilder[F]
30+
.bindSocketAddress(inetSocketAddress)
31+
.withHttpApp(httpApp)
32+
.withExecutionContext(executionContext)
33+
.withoutBanner
34+
.withNio2(config.nio2Enabled)
35+
.withWebSockets(config.webSocketsEnabled)
36+
.enableHttp2(config.http2Enabled)
37+
.withResponseHeaderTimeout(Duration.fromNanos(config.responseHeaderTimeout.toNanos))
38+
.withIdleTimeout(Duration.fromNanos(config.idleTimeout.toNanos))
39+
.withBufferSize(config.bufferSize)
40+
.withMaxRequestLineLength(config.maxRequestLineLength)
41+
.withMaxHeadersLength(config.maxHeadersLength)
42+
.withChunkBufferMaxSize(config.chunkBufferMaxSize)
43+
.withConnectorPoolSize(config.connectorPoolSize)
44+
.withChannelOption[java.lang.Boolean](StandardSocketOptions.TCP_NODELAY, config.socketOptions.tcpNoDelay)
45+
.resource
46+
} yield server
4047
}
41-
4248
}

http4s-server/src/test/scala/com/avast/sst/http4s/server/middleware/CorrelationIdMiddlewareTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.scalatest.funsuite.AsyncFunSuite
1313

1414
import scala.concurrent.ExecutionContext
1515

16-
@SuppressWarnings(Array("scalafix:Disable.get", "scalafix:Disable.toString"))
16+
@SuppressWarnings(Array("scalafix:Disable.get", "scalafix:Disable.toString", "scalafix:Disable.createUnresolved"))
1717
class CorrelationIdMiddlewareTest extends AsyncFunSuite with Http4sDsl[IO] {
1818

1919
implicit private val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global)

0 commit comments

Comments
 (0)