Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lintChecks with AGP7 #56

Open
androideveloper opened this issue Sep 10, 2021 · 5 comments
Open

lintChecks with AGP7 #56

androideveloper opened this issue Sep 10, 2021 · 5 comments

Comments

@androideveloper
Copy link

We are currently migrating to AGP 7 and noticed that our custom lint rules are not included in the lint checks.
We previously included them using lintChecks project(":libraries:lint-rules") and we only need them for local code check, so no publishing needed. Is there anything specific that needs to be changed to make it work with AGP 7?

@tnorbye
Copy link
Collaborator

tnorbye commented Sep 10, 2021

Do you mean that they're not packaged (e.g. the AAR file does not contain a lint.jar) or that somehow the checks aren't working/being applied?

@androideveloper
Copy link
Author

the checks aren't working/being applied

this.

An example of a lint check we have is below. And to test the setup, we previously added a usage of SimpleDateFormat and could see it in the lint report. After updating to AGP 7 we don't see it in the lint report.

@Suppress("UnstableApiUsage")
class LegacyDateNamingPatternDetector : Detector(), Detector.UastScanner {
    override fun getApplicableUastTypes() = listOf(UImportStatement::class.java)

    override fun createUastHandler(context: JavaContext) = LegacyDateInvalidImportHandler(context)
}

class LegacyDateInvalidImportHandler(private val context: JavaContext) : UElementHandler() {
    override fun visitImportStatement(node: UImportStatement) {
        node.importReference?.let { importReference ->
            if (importReference.asSourceString().contains("java.text.SimpleDateFormat")) {
                context.report(IssueLegacyDateImport, node, context.getLocation(importReference), "Forbidden import of Legacy Date API")
            }
        }
    }
}


class IssueRegistry : IssueRegistry() {
    override val issues: List<Issue> = listOf(
        IssueLegacyDateImport,
        IssueContextCompatIncorrectUsage
    )

    override val api: Int = CURRENT_API

    override val vendor: Vendor = Vendor(
        vendorName = "placeholder",
        feedbackUrl = "placeholder",
        contact = "placeholder"
    )
}

val IssueLegacyDateImport = Issue.create(
    id = "LegacyDateImport",
    briefDescription = "Old Java date APIs used",
    explanation = "Use Java 8 dates instead. See DateTimeExt class for more info.",
    category = CORRECTNESS,
    priority = 5,
    severity = Severity.WARNING,
    implementation = Implementation(
        LegacyDateNamingPatternDetector::class.java,
        EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES)
    )
)

@glorinli
Copy link

Same issue with AGP 7.0.3 and lint 30.0.3.

@glorinli
Copy link

I figured out that in my case it's caused by the maven publish plugin since I used third party maven plugin and seems it doesn't work well with AGP 7.0.3.

It's ok when I switch to builtin maven-publish plugin.

@apkelly
Copy link

apkelly commented Jan 13, 2022

I have the same problem, but I'm not using the maven-publish plugin at all, and I'm not publishing my lint checks via a library module, I'm just using them locally.

I am using kotlin for my build scripts, not groovy.....would that make a difference?

Android Studio Bumblebee | 2021.1.1 Beta 4
AGP=7.1.0-beta04
Lint=30.1.0-beta04

I've literally just included the code from this repo and have a Log.println() in my MainActivity which doesn't get highlighted when I run ./gradlew lintDebug or inside Android Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants