Skip to content

Instantly share code, notes, and snippets.

@euri16
Created June 9, 2025 15:45
Show Gist options
  • Select an option

  • Save euri16/2f907f6b56d2bcd588765f6f9881e5cf to your computer and use it in GitHub Desktop.

Select an option

Save euri16/2f907f6b56d2bcd588765f6f9881e5cf to your computer and use it in GitHub Desktop.
class LaunchedEffectWithEffectParamRule(config: Config) : Rule(config) {
// ...
override fun visitCallExpression(expression: KtCallExpression) {
super.visitCallExpression(expression)
val calleeName = expression.calleeExpression?.text ?: return
if (calleeName != "LaunchedEffect") return
val argumentList = expression.valueArguments
if (argumentList.isEmpty()) return
val firstArg = argumentList.first().text
// Check if any of the common effect-like names is present in the argument
if (effectNameCandidates.any { name -> firstArg.contains(name, ignoreCase = true) }) {
report(
CodeSmell(
issue,
Entity.from(expression),
message = "Consider using LaunchedUiEffectHandler instead of manually " +
"handling one-off events with LaunchedEffect and effect-related " +
"parameters.",
),
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment