Is there an easy way to stop any stdlib functions from being imported automatically? I just got bit again when I accidentally used
value.toString()
instead of
value?.toString()
. I'm not a fan of
Any?.toString()
, and I'd like to just get rid of it locally if possible.
e
ephemient
11/04/2022, 4:12 PM
Copy code
import kotlin.toString as `-toString`
this should do what you want
r
Ruckus
11/04/2022, 4:33 PM
Indeed, that does, though I meant for the whole project when I meant locally. It's as easy to forget that import as it is to forget to add the
?
, so I would like to set it once and never have it bother me again. If there isn't a way to remove it, is there a way to mark it as an error / warning?
e
ephemient
11/04/2022, 4:38 PM
1, there isn't a way. 2, you could probably write a #ktlint rule; outside of a framework like that, you'll have to do the work of figuring out type resolution yourself
r
Ruckus
11/04/2022, 6:13 PM
Fair enough. Thanks
e
ephemient
11/04/2022, 8:06 PM
actually now that I think more, #detekt would work better than ktlint since that's the one with optional type resolution