Skip to content

Commit 6425b80

Browse files
authored
Change strict mode to level ERROR by default (#338)
1 parent aed0e80 commit 6425b80

File tree

8 files changed

+67
-24
lines changed

8 files changed

+67
-24
lines changed

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ object StrictModeConfigurationKeys {
4949

5050
fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator {
5151
return StrictModeAggregator(
52-
stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.WARNING),
53-
sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.WARNING),
54-
nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.WARNING),
55-
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.WARNING),
56-
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.WARNING),
57-
notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.WARNING),
58-
fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.WARNING),
52+
stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.ERROR),
53+
sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.ERROR),
54+
nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.ERROR),
55+
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.ERROR),
56+
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.ERROR),
57+
notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.ERROR),
58+
fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.ERROR),
5959
)
6060
}
6161

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class RpcStrictModeDiagnosticRendererFactory(
140140
StrictMode.ERROR -> "prohibited"
141141
}
142142

143-
return "$entityName is $actionWord in @Rpc services in strict mode."
143+
return "$entityName is $actionWord in @Rpc services in strict mode. " +
144+
"Support will be removed completely in the 0.8.0 release."
144145
}
145146
}

docs/pages/kotlinx-rpc/topics/strict-mode.topic

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
Starting with version <code>0.5.0</code>, the library introduces major changes to the service APIs.
1414
The following declarations will be gradually restricted:
1515
</p>
16+
<warning>
17+
String mode will be enforced in the <code>0.8.0</code> release.
18+
</warning>
1619
<chapter title="StateFlow and SharedFlow" id="stateflow-and-sharedflow">
17-
<p>Deprecation level: <code>WARNING</code></p>
20+
<p>Deprecation level: <code>ERROR</code></p>
1821
<code-block lang="kotlin">
1922
@Rpc
2023
interface Service : RemoteService {
@@ -26,7 +29,7 @@
2629
</chapter>
2730

2831
<chapter title="Fields" id="fields">
29-
<p>Deprecation level: <code>WARNING</code></p>
32+
<p>Deprecation level: <code>ERROR</code></p>
3033
<code-block lang="kotlin">
3134
@Rpc
3235
interface Service : RemoteService {
@@ -37,7 +40,7 @@
3740
</code-block>
3841
</chapter>
3942
<chapter title="Nested Flows" id="nested-flows">
40-
<p>Deprecation level: <code>WARNING</code></p>
43+
<p>Deprecation level: <code>ERROR</code></p>
4144
<code-block lang="kotlin">
4245
@Rpc
4346
interface Service : RemoteService {
@@ -48,7 +51,7 @@
4851
</code-block>
4952
</chapter>
5053
<chapter title="Not top-level server flows" id="not-top-level-server-flows">
51-
<p>Deprecation level: <code>WARNING</code></p>
54+
<p>Deprecation level: <code>ERROR</code></p>
5255

5356
<code-block lang="kotlin">
5457
data class SpotifyWrapped(val myMusicFlow: Flow&lt;Rap&gt;, val extra: Data)
@@ -64,7 +67,7 @@
6467
</code-block>
6568
</chapter>
6669
<chapter title="Non-suspending server flows" id="non-suspending-server-flows">
67-
<p>Deprecation level: <code>WARNING</code></p>
70+
<p>Deprecation level: <code>ERROR</code></p>
6871

6972
<code-block lang="kotlin">
7073
data class SpotifyWrapped(val extra: Data)
@@ -78,7 +81,7 @@
7881
</code-block>
7982
</chapter>
8083
<chapter title="Stream scopes management" id="stream-scopes-management">
81-
<p>Deprecation level: <code>WARNING</code></p>
84+
<p>Deprecation level: <code>ERROR</code></p>
8285

8386
<p>
8487
The next stream scope management structures are deprecated due to the introduction of
@@ -158,18 +161,18 @@
158161

159162
rpc {
160163
strict {
161-
stateFlow = RpcStrictMode.WARNING
162-
sharedFlow = RpcStrictMode.WARNING
163-
nestedFlow = RpcStrictMode.WARNING
164-
notTopLevelServerFlow = RpcStrictMode.WARNING
165-
fields = RpcStrictMode.WARNING
166-
suspendingServerStreaming = RpcStrictMode.WARNING
167-
streamScopedFunctions = RpcStrictMode.WARNING
164+
stateFlow = RpcStrictMode.ERROR
165+
sharedFlow = RpcStrictMode.ERROR
166+
nestedFlow = RpcStrictMode.ERROR
167+
notTopLevelServerFlow = RpcStrictMode.ERROR
168+
fields = RpcStrictMode.ERROR
169+
suspendingServerStreaming = RpcStrictMode.ERROR
170+
streamScopedFunctions = RpcStrictMode.ERROR
168171
}
169172
}
170173
</code-block>
171174
<p>
172-
Modes <code>RpcStrictMode.NONE</code> and <code>RpcStrictMode.ERROR</code> are available.
175+
Modes <code>RpcStrictMode.NONE</code> and <code>RpcStrictMode.WARNING</code> are available.
173176
</p>
174177

175178
<warning>

gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
9191
val fields: Property<RpcStrictMode> = objects.strictModeProperty()
9292

9393
private fun ObjectFactory.strictModeProperty(
94-
default: RpcStrictMode = RpcStrictMode.WARNING,
94+
default: RpcStrictMode = RpcStrictMode.ERROR,
9595
): Property<RpcStrictMode> {
9696
return property(RpcStrictMode::class.java).convention(default)
9797
}

krpc/krpc-client/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import kotlinx.rpc.RpcStrictMode
56
import util.applyAtomicfuPlugin
67

78
plugins {
@@ -26,3 +27,15 @@ kotlin {
2627
}
2728
}
2829
}
30+
31+
rpc {
32+
strict {
33+
stateFlow = RpcStrictMode.NONE
34+
sharedFlow = RpcStrictMode.NONE
35+
nestedFlow = RpcStrictMode.NONE
36+
streamScopedFunctions = RpcStrictMode.NONE
37+
suspendingServerStreaming = RpcStrictMode.NONE
38+
notTopLevelServerFlow = RpcStrictMode.NONE
39+
fields = RpcStrictMode.NONE
40+
}
41+
}

krpc/krpc-core/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import kotlinx.rpc.RpcStrictMode
56
import util.applyAtomicfuPlugin
67

78
plugins {
@@ -27,3 +28,15 @@ kotlin {
2728
}
2829
}
2930
}
31+
32+
rpc {
33+
strict {
34+
stateFlow = RpcStrictMode.NONE
35+
sharedFlow = RpcStrictMode.NONE
36+
nestedFlow = RpcStrictMode.NONE
37+
streamScopedFunctions = RpcStrictMode.NONE
38+
suspendingServerStreaming = RpcStrictMode.NONE
39+
notTopLevelServerFlow = RpcStrictMode.NONE
40+
fields = RpcStrictMode.NONE
41+
}
42+
}

krpc/krpc-test/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import kotlinx.rpc.RpcStrictMode
56
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
67
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
78
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
@@ -100,3 +101,15 @@ tasks.register("moveToGold") {
100101
}
101102
}
102103
}
104+
105+
rpc {
106+
strict {
107+
stateFlow = RpcStrictMode.NONE
108+
sharedFlow = RpcStrictMode.NONE
109+
nestedFlow = RpcStrictMode.NONE
110+
streamScopedFunctions = RpcStrictMode.NONE
111+
suspendingServerStreaming = RpcStrictMode.NONE
112+
notTopLevelServerFlow = RpcStrictMode.NONE
113+
fields = RpcStrictMode.NONE
114+
}
115+
}

tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentCo
2727
) {
2828
val strictMode = module.directives[RpcDirectives.RPC_STRICT_MODE]
2929
if (strictMode.isNotEmpty()) {
30-
val mode = StrictMode.fromCli(strictMode.single()) ?: StrictMode.WARNING
30+
val mode = StrictMode.fromCli(strictMode.single()) ?: StrictMode.ERROR
3131
configuration.put(StrictModeConfigurationKeys.STATE_FLOW, mode)
3232
configuration.put(StrictModeConfigurationKeys.SHARED_FLOW, mode)
3333
configuration.put(StrictModeConfigurationKeys.NESTED_FLOW, mode)

0 commit comments

Comments
 (0)