Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Created January 2, 2020 13:49
Show Gist options
  • Save fbcbl/3e8b4a0e69a0b8f18111198ce5d5ac63 to your computer and use it in GitHub Desktop.
Save fbcbl/3e8b4a0e69a0b8f18111198ce5d5ac63 to your computer and use it in GitHub Desktop.
Android Lint - AndroidLogDetector
class AndroidLogDetector : Detector(), SourceCodeScanner {
override fun getApplicableMethodNames(): List<String> =
listOf("tag", "format", "v", "d", "i", "w", "e", "wtf")
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
super.visitMethodCall(context, node, method)
val evaluator = context.evaluator
if (evaluator.isMemberInClass(method, "android.util.Log")) {
reportUsage(context, node)
}
}
private fun reportUsage(context: JavaContext, node: UCallExpression) {
context.report(
issue = ISSUE,
scope = node,
location = context.getCallLocation(
call = node,
includeReceiver = true,
includeArguments = true
),
message = "android.util.Log usage is forbidden."
)
}
(...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment