Skip to content

Instantly share code, notes, and snippets.

@creativedrewy
Created January 11, 2019 22:18
Show Gist options
  • Save creativedrewy/37ca5559162a55e7544976df275d5ac7 to your computer and use it in GitHub Desktop.
Save creativedrewy/37ca5559162a55e7544976df275d5ac7 to your computer and use it in GitHub Desktop.
//BLOCK comment lint rule
class BlockCommentDetector : Detector(), Detector.UastScanner {
companion object {
val ISSUE: Issue = Issue.create(
"BlockComment",
"BLOCK comment found, cannot continue build.",
"Please resolve all BLOCK commented code before merging.",
Category.CORRECTNESS,
6,
Severity.ERROR,
Implementation(BlockCommentDetector::class.java, Scope.JAVA_FILE_SCOPE)
)
}
override fun getApplicableUastTypes(): MutableList<Class<out UElement>> {
return mutableListOf(UFile::class.java)
}
override fun createUastHandler(context: JavaContext): UElementHandler {
return object : UElementHandler() {
override fun visitFile(node: UFile) {
node.allCommentsInFile
.filter { it.text.startsWith("//BLOCK") || it.text.startsWith("// BLOCK") }
.forEach { comment ->
context.report(ISSUE, context.getLocation(comment), "Resolve all BLOCK commented code before merging.")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment