Pattern: Wrong class content order
Issue: -
Ensures class contents are ordered as follows as recommended by the Kotlin Coding Conventions:
- Property declarations and initializer blocks
- Secondary constructors
- Method declarations
- Companion object
Example of incorrect code:
class OutOfOrder {
companion object {
const val IMPORTANT_VALUE = 3
}
fun returnX(): Int {
return x
}
private val x = 2
}
Example of correct code:
class InOrder {
private val x = 2
fun returnX(): Int {
return x
}
companion object {
const val IMPORTANT_VALUE = 3
}
}