Running & Testing Lint Checks in Specific Directories

36 views
Skip to first unread message

Zachary Sperske

unread,
Jun 7, 2021, 7:44:56 AM6/7/21
to lint-dev
I'm working on a lint check that analyzes vector resources and will fail if the vector is not using a theme attribute from a provided set of attributes ie `android:fillColor="?attr/icon_primary_color"`.

I only want this check to run in a particular resource directory (design-system/icons/drawable). My gradle module has other directories that I don't want the check to run in.

I can simply restrict the path by hardcoding a check into my Detectors `visitAttribute` method, however that will cause my tests to start failing because they use paths like:

lint().files(
xml("res/drawable/test__icon.xml"

If you try and muck with the file path in the test, the detector will no longer run when the test runs.

Is there something in the test API that I am missing to allow paths that are more specific? Are there better ways to limit what directory my lint check runs in? I find myself wanting the ability to add parameters to my lint check but am I missing a simpler solution?

Tor Norbye

unread,
Jul 14, 2021, 8:20:44 PM7/14/21
to lint-dev
If I understand correctly you want to make sure that the created test project is also under design-system/icons/drawable ? If you're simply looking for that to be somewhere in the parent you could set a particular root directory for the test.

class SomeTest {
    @get:Rule
    var temporaryFolder = TemporaryFolder()

    fun `some test`() {
        val root = temporaryFolder.newFolder("design-system/icons/drawable")
        lint().files(
            ....
        )
       .rootDirectory(root)
       .run()
       .expect( .... )

-- Tor
Reply all
Reply to author
Forward
0 new messages