Skip to content

Instantly share code, notes, and snippets.

@erdemtopak
Created August 1, 2019 13:55
Show Gist options
  • Save erdemtopak/a6665f84ce13a090efc399e0b37dfd4c to your computer and use it in GitHub Desktop.
Save erdemtopak/a6665f84ce13a090efc399e0b37dfd4c to your computer and use it in GitHub Desktop.
Ktlint rule for `!!` (not-null assertion operator)
import com.github.shyiko.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.lexer.KtTokens.EXCLEXCL
class NoNotNullAssertionOperator : Rule("no-notnull-assertion") {
override fun visit(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
if (node.elementType == EXCLEXCL) {
emit(node.startOffset, "Using non-safe !! operator is not permitted", false)
}
}
}
@alandoni
Copy link

alandoni commented Mar 1, 2023

how do I use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment