check we have to roughly follow these steps: › Create a Lint Issue. › Register the Issue so lint can track it. › Create a detector for the Issue. › Report the Issue.
check we have to roughly follow these steps: › Create a Lint Issue. › Register the Issue so lint can track it. › Create a detector for the Issue. › Report the Issue. › [Optional] Provide a fix.
to the lint issue registry: class MyIssueRegistry : IssueRegistry() {k override val issues: List<Issue> = listOf(MyDetector.ISSUE) override val api: Int = CURRENT_API override val minApi: Int = MIN_API companion object {k const val MIN_API = 2 // Corresponds to android gradle plugin 3.2+ }k }k
to the lint issue registry: @AutoService(IssueRegistry::class) class MyIssueRegistry : IssueRegistry() {k override val issues: List<Issue> = listOf(MyDetector.ISSUE) override val api: Int = CURRENT_API override val minApi: Int = MIN_API companion object {k const val MIN_API = 2 // Corresponds to android gradle plugin 3.2+ }k }k
which makes a lot easier to write checks: › XmlScanner: lets you visit the XML file with DOM. › SourceCodeScanner: useful for Kotlin/Java analysis. › ClassScanner, BinaryResourceScanner, ResourceFolderScanner…
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k … } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k … } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
getApplicableUastTypes(): MutableList<Class<out UElement>> = mutableListOf(UMethod::class.java) override fun createUastHandler(context: JavaContext): UElementHandler = InferredTypeHandler(context) class InferredTypeHandler(private val context: JavaContext) : UElementHandler() { ... override fun visitMethod(node: UMethod) { if (!isKotlin(node)) return if (isInferredMethod(node)){ report(context) } k } k ... } k
using: › BaseFragment within a package. › Internal APIs to recommend to use a custom subscriber. › Nesting in lambdas. › Nesting in custom LiveData. › Top level class comments. › Internal deprecations.