|
|
|
We're using the official Kotlin style guide to format our source code.
|
|
|
|
|
|
|
|
To enforce this, we do have a Gradle task for checking that the style guide is met and another task for formatting the code base.
|
|
|
|
|
|
|
|
You can run these tasks from the command line like this:
|
|
|
|
```
|
|
|
|
./gradlew ktLintCheck
|
|
|
|
./gradlew ktLintFormat
|
|
|
|
```
|
|
|
|
|
|
|
|
These tasks have also been added as run configurations to the IDEA project, so that you can
|
|
|
|
run them directly from IntelliJ. Just select the respective task and hit the green play icon.
|
|
|
|
|
|
|
|
When inspecting errors found by those tasks, it is important to select the top-level item in the
|
|
|
|
run view, otherwise you won't be able to find the actual errors that the task found. By default a different item is selected in that view. Select the topmost item as in this screenshot:
|
|
|
|
|
|
|
|
![Screenshot_from_2021-09-13_08-57-26](uploads/a90e3c39ad6c4682a6804070ae921f33/Screenshot_from_2021-09-13_08-57-26.png)
|
|
|
|
|
|
|
|
## Wildcard imports
|
|
|
|
|
|
|
|
The Kotlin style guide does not allow wildcard imports. When getting rid of them, you can reimport the objects that are not being imported clicking the word in the editor, press `Alt-Enter` and select `import`.
|
|
|
|
|
|
|
|
For some reason, when using `mutableStateOf`, it does not suffice to import
|
|
|
|
```
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
```
|
|
|
|
|
|
|
|
but we also need to add those two imports, which does not happen automatically:
|
|
|
|
|
|
|
|
```
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
```
|
|
|
|
|