Using the `!!` operator seems to be a frequent sou...
# announcements
j
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
I'm scared of this operator and my friends are scared of this too but lint rule would be awesome
j
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
I feel that if a lint rule is added, people will start doing
Copy code
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
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
Detekt has this as a rule, and allows easy Suppression of rules if it’s determined to be valid/acceptable.
j
I like that idea.
j
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.