From 149bfc6fabc0f7d6403e8ee508a66e2af618768f Mon Sep 17 00:00:00 2001 From: drinkthestars <2978958+drinkthestars@users.noreply.github.com> Date: Tue, 23 Nov 2021 15:10:23 -0800 Subject: [PATCH] Add two new config steps for Compose (#4322) * Added two new configs for Compose * Added contributor entry to README * Clarify wording of FunctionNaming config --- README.md | 1 + docs/pages/compose.md | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6453766de..e76f736e0 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,7 @@ If you contributed to detekt but your name is not in the list, please feel free - [Hans-Martin Schuller](https://github.com/hmSchuller) - Rule Improvement: ForbiddenComment - [Lukasz Osowicki](https://github.com/lukaszosowicki) - New rule: OutdatedDocumentation - [Luan Nico](https://github.com/luanpotter) - Bug fix for the UselessCallOnNotNull rule +- [Tasha Ramesh](https://github.com/drinkthestars) - Docs around configuring for Compose ### Mentions diff --git a/docs/pages/compose.md b/docs/pages/compose.md index 4840e3d73..40ad26891 100644 --- a/docs/pages/compose.md +++ b/docs/pages/compose.md @@ -11,6 +11,23 @@ Relevant rule sets and their configuration options for Compose styles & usage. T - [Compose API Guidelines](https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-api-guidelines.md) - [Compose source](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose) +### FunctionNaming + +See [FunctionNaming](https://detekt.github.io/detekt/naming.html#functionnaming). + +``@Composable`` functions that return ``Unit`` are named using ``PascalCase``. Detekt may see this as a violation: + +``` kotlin +@Composable +fun FooButton(text: String, onClick: () -> Unit) { // Violation for FooButton() +``` + +#### Configurations: +Choose _either_ of the following options: + +* Augment default ``functionPattern`` to ``'([A-Za-z][a-zA-Z0-9]*)|(`.*`)'`` (default: ``'([a-z][a-zA-Z0-9]*)|(`.*`)'``) +* Set ``ignoreAnnotated`` to ``['Composable']`` + ### TopLevelPropertyNaming See [TopLevelPropertyNaming](https://detekt.github.io/detekt/naming.html#toplevelpropertynaming). @@ -65,4 +82,22 @@ class Foo { #### Configurations: -* Set ``ignorePropertyDeclaration = true``, ``ignoreCompanionObjectPropertyDeclaration = true`` (default) \ No newline at end of file +* Set ``ignorePropertyDeclaration = true``, ``ignoreCompanionObjectPropertyDeclaration = true`` (default) + +### UnusedPrivateMember + +See [UnusedPrivateMember](https://detekt.github.io/detekt/style.html#unusedprivatemember). + +Detekt may see composable preview functions, i.e. those marked with ``@Preview``, as unused. + +``` kotlin +@Preview +@Composable +private fun FooLazyColumnPreview() { // Violation for FooLazyColumnPreview() + FooLazyColumn() +} +``` + +#### Configurations: + +* Set ``ignoreAnnotated`` to ``['Preview']``