https://kotlinlang.org logo
Title
j

Jacques Smuts

06/10/2019, 10:34 AM
Using the
!!
operator seems to be a frequent source of issues. Has anyone here ever considered turning
!!
into a compiler-error lint rule?
👍 4
s

Sławomir Onyszko

06/10/2019, 10:40 AM
I'm scared of this operator and my friends are scared of this too but lint rule would be awesome
j

Jacques Smuts

06/10/2019, 10:53 AM
I’m not used to writing my own lint rules but this should be an easy one 🤔 . But it’s quite a hard-rule so not sure if it’s a good idea
l

LeoColman

06/10/2019, 12:05 PM
I feel that if a lint rule is added, people will start doing
val foo = getPossibleNullable() ?: throw IllegalStateException("Shouldn't be null")
Which would be exactly the same
Sometimes you just know a variable won't be null at some point, and I believe it's ok to go
!!
for that scenario
2
s

streetsofboston

06/10/2019, 12:14 PM
Using
!!
shouldn't be a Lint warning, but you should carefully examine your code why you'd need it! Often it's a code-smell, but sometimes there's no other way 😀
1
💯 1
m

Mike

06/10/2019, 1:09 PM
Detekt has this as a rule, and allows easy Suppression of rules if it’s determined to be valid/acceptable.
j

Jacques Smuts

06/10/2019, 1:11 PM
I like that idea.
j

Jessie

06/10/2019, 3:27 PM
I didn’t know we can create our own Lint rules, that’d be a great idea, but what we’ve done is that we don’t allow the
!!
operator, so in our code review we are really aware about it. We prefer to have a null check before using an expression that is coming from Java and might need that dangerous operator.