ignoreAnnotated does not recognize Compose multipreview annotations
#9.562 geöffnet am 01.08.2026
Repository-Metriken
- Stars
- (6.942 Sterne)
- PR-Merge-Metriken
- (PR-Metriken ausstehend)
Beschreibung
Expected Behavior
When a rule is configured with:
ignoreAnnotated:
- Preview
functions annotated with a Compose multipreview annotation should also be ignored when that annotation is itself annotated with @Preview.
For example:
@Preview(name = "Light")
@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES)
annotation class AppPreviews
@AppPreviews
@Composable
private fun ExamplePreview() = Unit
This would also cover official Compose multipreview annotations such as @PreviewLightDark.
Current Behavior
ignoreAnnotated matches only annotations directly present on the declaration. UnusedPrivateFunction therefore still reports ExamplePreview, and the annotation name must be added explicitly:
ignoreAnnotated:
- Preview
- AppPreviews
- PreviewLightDark
Detekt's Compose guidance currently recommends ignoring Preview without noting that multipreview annotations require separate entries.
Context
Compose supports custom multipreview annotations by annotating an annotation class with one or more @Preview annotations. Treating these preview functions as ordinary unused private functions creates false positives and baseline entries.
If recursively recognizing meta-annotations is not desirable for ignoreAnnotated, documenting the direct-only behavior and updating the Compose guidance for multipreview annotations would still help.
- Detekt Compose guidance: https://detekt.dev/docs/2.0.0-alpha.5/introduction/compose/#unusedprivatefunction-for-compose
- Compose multipreview documentation: https://developer.android.com/develop/ui/compose/tooling/previews#multi-preview