From ca6dc5480d8010d3d5e3bfa2fd41aa305ab65d78 Mon Sep 17 00:00:00 2001
From: Alexander Sysoev
Date: Tue, 13 May 2025 14:02:35 +0200
Subject: [PATCH] Change strict mode to level ERROR by default
---
.../core/kotlinx/rpc/codegen/StrictMode.kt | 14 ++++-----
.../RpcDiagnosticRendererFactory.kt | 3 +-
.../kotlinx-rpc/topics/strict-mode.topic | 31 ++++++++++---------
.../src/main/kotlin/kotlinx/rpc/Extensions.kt | 2 +-
krpc/krpc-client/build.gradle.kts | 13 ++++++++
krpc/krpc-core/build.gradle.kts | 13 ++++++++
krpc/krpc-test/build.gradle.kts | 13 ++++++++
.../ExtensionRegistrarConfigurator.kt | 2 +-
8 files changed, 67 insertions(+), 24 deletions(-)
diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt
index bec06d161..b8e4ca918 100644
--- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt
+++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt
@@ -49,13 +49,13 @@ object StrictModeConfigurationKeys {
fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator {
return StrictModeAggregator(
- stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.WARNING),
- sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.WARNING),
- nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.WARNING),
- streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.WARNING),
- suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.WARNING),
- notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.WARNING),
- fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.WARNING),
+ stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.ERROR),
+ sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.ERROR),
+ nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.ERROR),
+ streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.ERROR),
+ suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.ERROR),
+ notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.ERROR),
+ fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.ERROR),
)
}
diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt
index 17851071c..2717da2aa 100644
--- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt
+++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt
@@ -140,6 +140,7 @@ class RpcStrictModeDiagnosticRendererFactory(
StrictMode.ERROR -> "prohibited"
}
- return "$entityName is $actionWord in @Rpc services in strict mode."
+ return "$entityName is $actionWord in @Rpc services in strict mode. " +
+ "Support will be removed completely in the 0.8.0 release."
}
}
diff --git a/docs/pages/kotlinx-rpc/topics/strict-mode.topic b/docs/pages/kotlinx-rpc/topics/strict-mode.topic
index 9053e22d5..0d512e3ba 100644
--- a/docs/pages/kotlinx-rpc/topics/strict-mode.topic
+++ b/docs/pages/kotlinx-rpc/topics/strict-mode.topic
@@ -13,8 +13,11 @@
Starting with version 0.5.0
, the library introduces major changes to the service APIs.
The following declarations will be gradually restricted:
+
+ String mode will be enforced in the 0.8.0
release.
+
- Deprecation level: WARNING
+ Deprecation level: ERROR
@Rpc
interface Service : RemoteService {
@@ -26,7 +29,7 @@
- Deprecation level: WARNING
+ Deprecation level: ERROR
@Rpc
interface Service : RemoteService {
@@ -37,7 +40,7 @@
- Deprecation level: WARNING
+ Deprecation level: ERROR
@Rpc
interface Service : RemoteService {
@@ -48,7 +51,7 @@
- Deprecation level: WARNING
+ Deprecation level: ERROR
data class SpotifyWrapped(val myMusicFlow: Flow<Rap>, val extra: Data)
@@ -64,7 +67,7 @@
- Deprecation level: WARNING
+ Deprecation level: ERROR
data class SpotifyWrapped(val extra: Data)
@@ -78,7 +81,7 @@
- Deprecation level: WARNING
+ Deprecation level: ERROR
The next stream scope management structures are deprecated due to the introduction of
@@ -158,18 +161,18 @@
rpc {
strict {
- stateFlow = RpcStrictMode.WARNING
- sharedFlow = RpcStrictMode.WARNING
- nestedFlow = RpcStrictMode.WARNING
- notTopLevelServerFlow = RpcStrictMode.WARNING
- fields = RpcStrictMode.WARNING
- suspendingServerStreaming = RpcStrictMode.WARNING
- streamScopedFunctions = RpcStrictMode.WARNING
+ stateFlow = RpcStrictMode.ERROR
+ sharedFlow = RpcStrictMode.ERROR
+ nestedFlow = RpcStrictMode.ERROR
+ notTopLevelServerFlow = RpcStrictMode.ERROR
+ fields = RpcStrictMode.ERROR
+ suspendingServerStreaming = RpcStrictMode.ERROR
+ streamScopedFunctions = RpcStrictMode.ERROR
}
}
- Modes RpcStrictMode.NONE
and RpcStrictMode.ERROR
are available.
+ Modes RpcStrictMode.NONE
and RpcStrictMode.WARNING
are available.
diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt
index 03f67af3b..c64ed04a0 100644
--- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt
+++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt
@@ -91,7 +91,7 @@ open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
val fields: Property = objects.strictModeProperty()
private fun ObjectFactory.strictModeProperty(
- default: RpcStrictMode = RpcStrictMode.WARNING,
+ default: RpcStrictMode = RpcStrictMode.ERROR,
): Property {
return property(RpcStrictMode::class.java).convention(default)
}
diff --git a/krpc/krpc-client/build.gradle.kts b/krpc/krpc-client/build.gradle.kts
index 21673c7f4..8b91ed2e6 100644
--- a/krpc/krpc-client/build.gradle.kts
+++ b/krpc/krpc-client/build.gradle.kts
@@ -2,6 +2,7 @@
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
+import kotlinx.rpc.RpcStrictMode
import util.applyAtomicfuPlugin
plugins {
@@ -26,3 +27,15 @@ kotlin {
}
}
}
+
+rpc {
+ strict {
+ stateFlow = RpcStrictMode.NONE
+ sharedFlow = RpcStrictMode.NONE
+ nestedFlow = RpcStrictMode.NONE
+ streamScopedFunctions = RpcStrictMode.NONE
+ suspendingServerStreaming = RpcStrictMode.NONE
+ notTopLevelServerFlow = RpcStrictMode.NONE
+ fields = RpcStrictMode.NONE
+ }
+}
diff --git a/krpc/krpc-core/build.gradle.kts b/krpc/krpc-core/build.gradle.kts
index b869df5dc..29040a7dc 100644
--- a/krpc/krpc-core/build.gradle.kts
+++ b/krpc/krpc-core/build.gradle.kts
@@ -2,6 +2,7 @@
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
+import kotlinx.rpc.RpcStrictMode
import util.applyAtomicfuPlugin
plugins {
@@ -27,3 +28,15 @@ kotlin {
}
}
}
+
+rpc {
+ strict {
+ stateFlow = RpcStrictMode.NONE
+ sharedFlow = RpcStrictMode.NONE
+ nestedFlow = RpcStrictMode.NONE
+ streamScopedFunctions = RpcStrictMode.NONE
+ suspendingServerStreaming = RpcStrictMode.NONE
+ notTopLevelServerFlow = RpcStrictMode.NONE
+ fields = RpcStrictMode.NONE
+ }
+}
diff --git a/krpc/krpc-test/build.gradle.kts b/krpc/krpc-test/build.gradle.kts
index b5cc28ea2..0ba1b3566 100644
--- a/krpc/krpc-test/build.gradle.kts
+++ b/krpc/krpc-test/build.gradle.kts
@@ -2,6 +2,7 @@
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
+import kotlinx.rpc.RpcStrictMode
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
@@ -100,3 +101,15 @@ tasks.register("moveToGold") {
}
}
}
+
+rpc {
+ strict {
+ stateFlow = RpcStrictMode.NONE
+ sharedFlow = RpcStrictMode.NONE
+ nestedFlow = RpcStrictMode.NONE
+ streamScopedFunctions = RpcStrictMode.NONE
+ suspendingServerStreaming = RpcStrictMode.NONE
+ notTopLevelServerFlow = RpcStrictMode.NONE
+ fields = RpcStrictMode.NONE
+ }
+}
diff --git a/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt b/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt
index 4907097d3..9b86738f1 100644
--- a/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt
+++ b/tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt
@@ -27,7 +27,7 @@ class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentCo
) {
val strictMode = module.directives[RpcDirectives.RPC_STRICT_MODE]
if (strictMode.isNotEmpty()) {
- val mode = StrictMode.fromCli(strictMode.single()) ?: StrictMode.WARNING
+ val mode = StrictMode.fromCli(strictMode.single()) ?: StrictMode.ERROR
configuration.put(StrictModeConfigurationKeys.STATE_FLOW, mode)
configuration.put(StrictModeConfigurationKeys.SHARED_FLOW, mode)
configuration.put(StrictModeConfigurationKeys.NESTED_FLOW, mode)