twitter / compose-rules

Static checks to aid with a healthy adoption of Compose
https://twitter.github.io/compose-rules
Other
1.37k stars 93 forks source link

False positives on expect / actual composable functions #81

Closed svenjacobs closed 2 years ago

svenjacobs commented 2 years ago

I'm currently developing a Kotlin Multiplatform application with a shared Compose UI for the Android and JVM platforms. Of course several Composables require platform-specific code so I'm using the expect / actual mechanism here. Some rules don't handle this correctly at the moment.

@Composable
expect fun PlatformSpecifcComposable(modifier: Modifier = Modifier)

@Composable
actual fun PlatformSpecifcComposable(modifier: Modifier) {
}

For instance on actual fun PlatformSpecifcComposable(modifier: Modifier) I now get the error

[twitter-compose:modifier-without-default-check] This @Composable function has a modifier parameter but it doesn't have a default value

Default values can only be specified at the expect level. Maybe other rules are also affected?

Twitter Compose Rules version 0.0.14.

mrmans0n commented 2 years ago

Good catch, thankfully the fix should be easy (adding a hasModifier("actual") to the list of exemptions the rule already has 😅 )