-
Notifications
You must be signed in to change notification settings - Fork 0
Setup Konsist module for enforcing architectural constraints #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Introduce `KonsistUtils.kt` with a `checkNoDirectUsageExceptAllowed` function to support these tests.
…CaScaffold`, `CaSurface`, and `CaTextField`. - Migrate existing UI elements in `composeApp` to use the new design system components. - Add tests to ensure that direct usage of `androidx.compose.material3` components is disallowed, promoting the use of the new design system components. - Mark the task "Create a separate module for reusable UI components" as complete in `README.md`.
- Replace direct usages of `material3.Text` with `KdText`. - Rename design system components from `Ca` prefix to `Kd` (e.g., `CaScaffold` to `KdScaffold`). - Add a test to prevent direct usage of `androidx.compose.material3.Text` outside the design system.
RajashekarRaju
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed 2 things
1. Ktlint
I believe checks are not happening in this new module, check why.
2. Guarding your screens by identifying which components are not declared
You know none of your screen code is still calling those wrappers directly. But there are dozens of other Material 3 APIs (e.g. AlertDialog, TopAppBar, TextButton, etc.) that also need to live in your design-system. To catch any you’ve missed, add a “global coverage” test:
@Test
fun `all material3 components have design-system wrappers`() {
val ignoreComponents = setOf(
"androidx.compose.material3.Typography",
)
checkAllMaterial3ComponentsMoved(
allowedComponents = ignoreComponents,
excludePaths = arrayOf(DESIGN_SYSTEM_PATH)
)
}And in your KonsistUtils.kt, add the helper that this test calls:
internal fun checkAllMaterial3ComponentsMoved(
allowedComponents: Set<String>,
excludePaths: Array<String> = emptyArray(),
) {
val files = Konsist
.scopeFromProject()
.files
.filter { file ->
val path = file.path.replace("\\", "/").lowercase()
excludePaths.none { path.contains(it.replace("\\", "/").lowercase()) }
}
val allMaterial3Imports = files
.flatMap { it.imports }
.map { it.name }
.filter { it.startsWith("androidx.compose.material3.") }
.distinct()
val pending = allMaterial3Imports - allowedComponents
assertTrue(
actual = pending.isEmpty(),
message = "Found pending Material3 components not in design-system:\n" +
pending.joinToString("\n") { " • $it" },
)
}- excludePaths makes sure you don’t flag your own wrapper files.
- allowedComponents is really an “ignore list” for things you don’t plan to wrap (typography, themes, annotations, etc.)
With this in place, every time you run your Konsist suite you’ll get a clear list of any Material 3 APIs still living in your app code rather than in design-system.
You can also guard from others declaring their own components, this is more like building a fool proof for your tests.
...pp/src/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/KonsistUtils.kt
Outdated
Show resolved
Hide resolved
...rc/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/DesignSystemTest.kt
Outdated
Show resolved
Hide resolved
design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Scaffold.kt
Show resolved
Hide resolved
design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Text.kt
Outdated
Show resolved
Hide resolved
…`KdCircularProgressIndicator`, and `KdTopAppBar`. - Add `modifier` parameter to existing design system components: `KdScaffold`, `KdText`, `KdIcon`, and `KdIconButton`. - Update Konsist tests to ensure all Material3 components are wrapped by the design system and exclude ktlint suppressed files. - Add ktlint plugin and dependency to `design-system` module. - Suppress ktlint for `platform.kt` files.
No description provided.