r/Kotlin • u/Content-Jaguar-578 • 2h ago
How should static analysis reason about Jetpack Compose modifier chains?
I've been exploring static analysis for Jetpack Compose, particularly around identifying layout patterns that can cause problems on tablets, foldables, and resizable windows.
One interesting challenge is deciding when a fixed dimension is actually a problem.
For example:
Box(
modifier = Modifier
.fillMaxWidth()
.height(600.dp)
)This might be perfectly intentional for a particular UI component. But in another context, it could result in clipping or poor space utilization on larger screens.
Similarly:
Modifier.requiredSize(400.dp)can override the normal constraints imposed by the parent.
The difficulty is that simply detecting calls such as height(), width(), or requiredSize() isn't enough to determine whether the code is problematic.
The surrounding modifier chain, parent constraints, and available adaptive mechanisms all matter.
I've been working on a small static analysis project using Kotlin and Gradle to explore these cases, and it has raised a few interesting questions:
- How much context should a static analysis rule consider before reporting a Compose layout issue?
- Is analyzing modifier chains sufficient, or should inspections also understand the surrounding composable structure?
- How would you approach reducing false positives when fixed dimensions are intentional?
- Would it make sense to model adaptive layout expectations as configurable rules rather than universal restrictions?
I'm particularly interested in how people approach these problems when building Kotlin-based static analysis tools.
Curious to hear your thoughts, especially from people who have worked with compiler plugins, PSI, UAST, or Compose tooling.