Personal lint rules and code convention
Rules | Checkstyle | KtLint |
---|---|---|
All name acronym | AbbreviationAsWordInName |
✓ |
Class body starting whitespace | ✗ | ✓ |
Functions return type | ✗ | ✓ |
Throw exception ambiguity | ✓ | ✓ |
Types Kotlin API | ✗ | ✓ |
Rules | Checkstyle | KtLint |
---|---|---|
Summary continuation | ✓ | ✓ |
Tag description sentence | ✓ | ✓ |
Tags starting whitespace | RequireEmptyLineBeforeBlockTagGroup |
✓ |
While uppercase acronym does comply with pascal-case naming standards, lowercase acronym is easier to read. However, only 3 connecting uppercase letters are flagged. This rule affects property, function, class-alike and even file.
val userJSON = "{ user: \"Hendra Anggrian\" }"
fun blendARGB()
class RestAPI
SQLUtility.kt
If a class' declaration is multiline and has a content, the first line of the
content should be an empty line. This rule affects all class-like objects
(class
, interface
, etc.).
class User(
username: String,
password: String
) {
override fun toString(): String = username
}
Prohibits declaration of public expression function and property accessor without return type.
fun getMessage() = "Hello World"
val message get() = "Hello World"
Throwing Exception
, Error
, and Throwable
require a detail message. Does
not apply to their subtypes (IllegalStateExeption
, StackOverflowError
, etc.)
as they are explicit enough.
throw Exception()
Avoid using API from java.*
and org.junit.*
where there are Kotlin
equivalents.
import java.lang.String
val images = java.util.ArrayList<Image>()
Every new line of continuation paragraph cannot start with link or code.
/**
* This is a superclass of all
* [cars] and
* `bikes`.
*/
interface Vehicle
This is a default behavior of markdown editor on IntelliJ IDEs.
Description of certain tags, if present, is in form of a sentence. Therefore,
must have one of end punctuations .
, !
, or ?
.
/**
* @param message a simple text
*/
fun send(message: String)
Both Javadoc and Kdoc recommend putting an empty space separating summary and tag group.
/**
* Insert an item to this collection.
* @param element item to add.
* @return true if element is successfully added.
*/
fun add(element: E): Boolean