VKCOM / vkompose

Kotlin Compiler Plugins, an IDEA Plugin, and a Detekt Rule that will help to improve your experience with Jetpack Compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vkcompose

Maven Central

The repository contains utilities for Jetpack Compose, including Kotlin compiler plugins, IDEA plugin, and a Detekt rule.

Kotlin Compiler Plugins

Compiler plugins support kotlin version from 1.8.10 to 1.9.22. Also you can try them for kotlin v2.0, but this version is not a stable release yet.

Currently, the following compiler plugins are available:

  • Functions skippability checker: Determines function skippability based on checking function parameters stability.
  • Recomposed function highlighter: Highlights recomposed functions with a colored border which increases the width when the recompositions count becomes larger. See here
  • Recomposed function reasons logger: Logs reasons for recomposed functions when arguments of that function has been changed. It's like a Rebugger, but automated. You don’t need to register the logger/rebugger in suspected problem areas every time
  • Test tag generator for Composable functions: Adds generated test tag for composable function if there is a default Modifier that does not have an applied testTag.
  • Test tag remover: Removes all test tags by replacing them with an empty string.
  • Test tag drawer: Draws test tags in a dialog for long tap. (It`s very experimental. I am looking for a better solution)
  • SourceInformation function calls remover: Yes, you can use sourceInformation option for Compose Compiler "-Pplugin:androidx.compose.compiler.plugins.kotlin:sourceInformation=false", but AGP enables that by default for debug builds. For AGP 8.4.0 see use Compose Compiler option. You can see fix here

How to use?

  1. Apply Gradle plugin
plugins {
    id("com.vk.vkompose") version "0.5"
}
  1. Enable and configure your desired features. For example:
vkompose {
    skippabilityCheck = true
    // or
    skippabilityCheck {
        // For more see
        // https://android-review.googlesource.com/c/platform/frameworks/support/+/2668595
        // https://issuetracker.google.com/issues/309765121
        stabilityConfigurationPath = "/path/file.config"
    }

    recompose {
        isHighlighterEnabled = true
        isLoggerEnabled = true
        // or
        logger {
            logModifierChanges = true // true by default since 0.5.0
            logFunctionChanges = true // true by default since 0.5.0. log when function arguments (like lambdas or function references) of composable function are changed
        }
    }

    testTag {
        isApplierEnabled = true
        isDrawerEnabled = false
        isCleanerEnabled = false
    }

    sourceInformationClean = true
}
  1. Enable some plugins in your application code
import com.vk.compose.test.tag.drawer.TestTagDrawConfig
import com.vk.recompose.highlighter.RecomposeHighlighterConfig
import com.vk.recompose.logger.RecomposeLoggerConfig

RecomposeLoggerConfig.isEnabled = true
RecomposeHighlighterConfig.isEnabled = true
TestTagDrawConfig.isEnabled = true

Besides these plugins are published separately. So if you want to use only one, you can do.

plugins {
    id("com.vk.recompose-highlighter") version "0.5"
    id("com.vk.recompose-logger") version "0.5"
    id("com.vk.compose-test-tag-applier") version "0.5"
    id("com.vk.compose-test-tag-cleaner") version "0.5"
    id("com.vk.compose-test-tag-drawer") version "0.5"
    id("com.vk.compose-source-information-cleaner") version "0.5"
    id("com.vk.composable-skippability-checker") version "0.5"
}

recomposeHighlighter {
    isEnabled = false // true by default
}

recomposeLogger {
    isEnabled = false // true by default
    logModifierChanges = true // true by default since 0.5.0
    logFunctionChanges = true // true by default since 0.5.0
}

composeTestTagApplier {
    isEnabled = false // true by default
}

composeTestTagCleaner {
    isEnabled = false // true by default
}

composeTestTagDrawer {
    isEnabled = false // true by default
}

composeSourceInformationCleaner {
    isEnabled = false // true by default
}

composableSkippabilityChecker {
    isEnabled = false // true by default
    stabilityConfigurationPath = "/path/file.config"
}

Also if you enable recompose logger, you can add logger manually function that track changes of arguments. For example:

import com.vk.recompose.logger.RecomposeLogger

RecomposeLogger(
    name = "Some Function Name",
    arguments = mapOf("param1" to param1, "param2" to param2),
)

And check logs with tag "RecomposeLogger". This already looks like the Rebugger is working.

IDEA Plugin

The IDEA plugin currently offers two features:

  • Error for unskippable functions and unstable parameters vkcompose-idea-plugin-skippability-error.gif

  • Marker for generated test tag values !vkcompose-idea-plugin-test-tag-marker.png

Both features can be disabled in preferences: vkompose-idea-plugin-preferences.png You can download and install it from the jar file for Hedgehog, Iguana, Jellyfish or Koala versions of AS.

Detekt Rule

There is one rule available that checks the skippability of functions. To use it, apply the dependency via the detektPlugin configuration in the dependencies block.

dependencies {
    detektPlugins("com.vk.vkompose:detekt:0.5")
}

Also you can disable checking some classes in detekt config file

vkompose:
  NonSkippableComposable:
    active: true
    ignoredClasses: [ 'kotlin.*', 'my.clazz.Data' ]

Known issues

  • Idea plugin does not allow to disable checking stability of some classes
  • Idea plugin cannot draw a test tag marker for functions from other libraries if they have a default Modifier value and Modifier is not explicitly passes as an argument. For more see KTIJ-27688

About

Kotlin Compiler Plugins, an IDEA Plugin, and a Detekt Rule that will help to improve your experience with Jetpack Compose

License:MIT License


Languages

Language:Kotlin 98.4%Language:Shell 1.6%