twitter / compose-rules

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

Preview composables should not be public doesn't work for @preview function without @PreviewParameter #119

Closed pokk closed 1 year ago

pokk commented 1 year ago

Describe the bug According to Preview composables should not be public, a preview function should give us a lint error/warning. However, it doesn't.

To Reproduce Steps to reproduce the behavior:

@Preview
@Composable
fun Preview() {
    MaterialTheme {
        TestScreen()
    }
}

Expected behavior It should have a lint error/warning for a public preview function.

Screenshots

2023-05-03-3-59-17 2023-05-03-4-01-17

Environment lib version: detekt-twitter-compose-0.0.26-all.jar Android Studio: Android Studio Giraffe | 2022.3.1 Beta 1 OS: macOs Ventura 13.3.1

Additional context Only a preview function with @PreviewParameter will have a lint error/warning.

https://github.com/twitter/compose-rules/blob/main/rules/common/src/main/kotlin/com/twitter/compose/rules/ComposePreviewPublic.kt#L22-L28 Just guessing, it might have the intention to do this. According to Preview composables should not be public, it doesn't describe clearly. Either one might be wrong 🤔

mtkw0127 commented 1 year ago

I'm also facing the same problem. I set previewPublicOnlyIfParams false. https://twitter.github.io/compose-rules/detekt/ related Issue: https://github.com/twitter/compose-rules/issues/95

  PreviewPublic:
    active: true
    # You can optionally disable that only previews with @PreviewParameter are flagged
    # previewPublicOnlyIfParams: false
mtkw0127 commented 1 year ago

Discussing here. https://github.com/mrmans0n/compose-rules/issues/24

pokk commented 1 year ago

Will close since there is the same discussion