-
Notifications
You must be signed in to change notification settings - Fork 2
Kotlin convention
BryanLee edited this page Jun 5, 2020
·
11 revisions
Basically, all rules are based on the following.
- https://developer.android.com/kotlin/style-guide
- https://kotlinlang.org/docs/reference/coding-conventions.html
For applying those rules programatically, I used ktlint.
Customed rules are below and I attached a link relate to the section.
- Need a new line between all elements
- Put related stuff together by visibility
- Declaration order is
public > internal > protected > private
in all area - For readability set API method for public and implement it with the protected or private keyword
val
val by lazy
var
lateinit var
- Prefer to use primary constructor first with arguments
private fun
fun
override fun
private fun
- Don't use an Uppercase letter more than 2 for class and method like not OEBPS but Oepbs.
- Don't use the abbreviation for the name of class and method if possible.
- The common term first then the concrete term.
- The key name follows
snake_case
- Convert
snake_case
resource id tocamelCase
variable through data binding. - The extra key has to start with the package name and be named
snake_case
if it's accesspublic
.
- Method name has to be started with
given_when_then
. - Use the abbreviation for the name of the variable if possible.
- Distinct
Arrange-Action-Assertion
area clearly in method.- Define input in Arrange
- Define
actual
andexpect
in Action - Define assertion with
actual
andexpect
- All test method has to be an independent task.
-
xxxPath()
method has to return with postfix of/
.