https://kotlinlang.org logo
#konsist
Title
# konsist
b

Bruno Rocha

11/07/2023, 2:38 PM
Hello apologies if this is not the right place but are there any plans to support getting .xml files also through the framework or the focus will be on Kotlin files? I'm trying to enforce certain styles of naming convention and the idea was to also check for example the drawables or navigation files in Android for the filename
i

igor.wojda

11/08/2023, 8:15 AM
For now focus is mostly on Kotlin however I have been thinking about supporting different formats. Please share few ideas, few specific tests that you would like to have
b

Bruno Rocha

11/08/2023, 5:17 PM
@igor.wojda The most important one right now in my mind would be to check prefixes of the xml files. For example find all the .xml files inside the navigation folder and then make sure every file has the prefix "nav_" . Something else that could be helpful is also going through the layout files and see if the prefixes match with what we want. Same idea for the drawables stuff
This is a basic test that achieves the case I'm trying to cover
Copy code
@Test
    fun `navigation files should have 'nav_' prefix`() {

        val projectPath = PathProvider.getInstance().rootProjectPath
        val path = "/module/src/main/res/navigation"
        val navigationDir = File(projectPath + path)

        navigationDir.listFiles()?.map { it.name }?.forEach {
            assert(it.startsWith("nav"))
        }
    }
i

igor.wojda

11/08/2023, 5:44 PM
please show me your nav XML, just for the complete sample
b

Bruno Rocha

11/08/2023, 6:01 PM
Copy code
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="<http://schemas.android.com/apk/res/android>"
    xmlns:app="<http://schemas.android.com/apk/res-auto>"
    xmlns:tools="<http://schemas.android.com/tools>"
    android:id="@+id/nav_graph_id"
    app:startDestination="@id/oneFragment">

    <fragment
        android:id="@+id/oneFragment"
        android:name="com.example.OneFragment"
        android:label=" "
        tools:layout="@layout/fragment_one">

        <action
            android:id="@+id/onError"
            app:destination="@+id/errorScreen"
            app:enterAnim="@anim/slide_in_bottom"
            app:exitAnim="@anim/slide_out_top"
            app:popEnterAnim="@anim/slide_in_top"
            app:popExitAnim="@anim/slide_out_bottom" />
    </fragment>

    <activity
        android:id="@+id/errorScreen"
        android:name="com.example.GenericErrorActivity"
        android:label=" "
        tools:layout="@layout/activity_generic_error" />
</navigation>
This is an example, there are a few more possible options for tags and arguments inside the file
Let me know if I can help
i

igor.wojda

11/08/2023, 6:08 PM
I really wonder about another approach mabye we could check generated classes in the
build
dir 🤔 (currently these are ignored by Konsist).
AFAIK these generated Kotlin classes (
build\generated
) should contain everything you need and Konsist should be able to retrieve all of the informations. Please check your build folder and tell me if this is correct
assumption
b

Bruno Rocha

11/08/2023, 7:07 PM
From what I can tell no Kotlin code related to navigation part is created. I dived a bit into the google code that interacts with the navigation and it's all done through an XML parser and then creating the objects for use at runtime