-
Notifications
You must be signed in to change notification settings - Fork 39
Code style rules — missing
-
Concatenation of Strings instead of Kotlin strings(added) -
need to put a space after and before braces { x -> x } (kumar to check)alreay exists inWhitespaceRule
-
creating methods for getters and setters in cases where properties would be more appropriate - is a bad styleimplemented in chapter 6 -
rules for labeling https://kotlinlang.org/docs/reference/returns.html#697 -
data classes - suggest to use them(added) -
Chapter 5: need to add rules related to goto: https://kotlinlang.org/docs/reference/returns.html#697 -
Do not use !isEmpty - use isNotEmpty instead#692 -
try not to use nested and inner classes in your code - WHY NOT??? At least because of this stuff: https://kotlinlang.org/docs/reference/classes.html#calling-the-superclass-implementation
-
Avoid if-null Checksimplemented asAVOID_NULL_CHECKS
-
use inline classes (https://kotlinlang.org/docs/reference/inline-classes.html)#698 -
Companion objects and interfaces. https://stackoverflow.com/questions/35327443/companion-objects-in-kotlin-interfaces Usage in interfaces and implementing interfaces. (What exactly can be checked here? Should we forbid companion objects in interfaces?)
-
Shadowing: Static analysis in Idea does not treat companion object and init blocks as shadowing
class BB(var a: String) { // parameters[3]
init {
var a = 0 // properties[1]
a = 5
}
companion object {
var a = 0 // properties[2]
}
fun foo(a: Int) { // parameters[4]
val a = 1 // properties[3]
}
}
-
Check Java Optional used in Kotlin: if Optional is used - then need to have proper construction with Kotlin: like
Optional.orElse(null) ?: {}
orOptional.orElse(null)?.let {}
-
there is difference between
.let
and.also
- static analyzer should check that the proper method is used. For example, if simple "print" is used - then no need for using also - should use let. https://kotlinlang.org/docs/reference/scope-functions.html - can be used as reference for describing the rule. (can't be done without type resolution? if returned value is unused, can bealso
, otherwise -let
?) -
missing rules about
===
-
missing rules about !(a == 5) - it should be replaced with a != 5
-
Long lambdas should have a parameter name instead of#695it
-
(not sure) Avoid using Boolean variable names with negative meaning:
isNotError
, conflicts with 7. Need to decide -
long x = y = 5 + 5; assignment in assignment(WTF, this is Java, this code doesn't compile in kotlin.var x = 2; val y = x = 2 + 2
doesn't compile too) -
simplification of logical conditions (general form of 17)
-
nested scope functions with receiver (
run
,with
,apply
) andthis
resolution - kotlin lets implicitly access outerthis
if there is no name clash, but it reduces readability -
allow
return
from first quarter (preconditions) or last quarter (return values) of function -
IMPORTANT: check for assignment in if statements! (same as 20 - kotlin says
assignments are not expressions and only expressions are allowed in this context
?)
25) Unused imports: if imports is w/o #710*
we can search for imported names in code.
-
What's with Kotlin JS?
-
What's with Kotlin Script