diktat icon indicating copy to clipboard operation
diktat copied to clipboard

New rule to check if @Preview (Jetpack Compose) functions end with 'Preview' suffix and are also private

Open WebTiger89 opened this issue 3 years ago • 1 comments
trafficstars

This is a common issue with Jetpack Compose and would be really convenient. Actually, this should be a resposnibility for android lint I guess but maybe you see potential here.

Description: In Jetpack Compose it is common to give your @Preview functions a 'Preview' suffix for example

@Preview
@Composable
private fun BannerPreview() {}

It's not so common to make them private but it should be. I had a discussion on slack, check https://kotlinlang.slack.com/archives/CJLTWPH7S/p1652276247920509

Sooner or later this will be adopted by android. If you think this is a good idea for 2 new rules, I'm glad to see it in a future version :)

WebTiger89 avatar May 27 '22 21:05 WebTiger89

Good rules for the future. Will be added after 1.2.0

orchestr7 avatar May 30 '22 14:05 orchestr7

It will be really useful to have a rule to check if Preview functions are called in the non preview functions.

mbalajee avatar Aug 30 '23 14:08 mbalajee

https://github.com/saveourtool/diktat/discussions/1725

orchestr7 avatar Aug 30 '23 14:08 orchestr7