slackhq / compose-lints

Lint checks to aid with a healthy adoption of Compose

Home Page:https://slackhq.github.io/compose-lints

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to suppress Lint warnings

juandiana opened this issue · comments

I'm not being able to suppress ComposeModifierMissing lint warnings

@SuppressLint("ComposeModifierMissing")
@Composable
fun Screen(
    onAbortButtonClicked: () -> Unit,
    onContinueButtonClicked: () -> Unit
)

Both, the lint task (gradlew lint) fails and Android Studio displays it with red underlines.

Android Studio version: Electric Eel 2022.1.1 Patch 1
AGP version: 7.4.1
Compose lint version: 1.0.0

Let me know if you need any more information to reproduce

I think this may be a bug in lint itself since compose modifies the function signature, you'll need to raise this on the android issue tracker as we don't control suppressibility. We can re-open if they say otherwise.

In the meantime, a possible workaround may be to use a baseline file instead.

We ran into this also. I reported the issue and pointed to this issue for reference.

Another possible workaround is that lint does support kotlin's @Suppress annotation too, so you could try that

No dice

Hmmmm, I went to investigate that bug (https://issuetracker.google.com/issues/318532624) and I can't reproduce it.

I opened the Slack lint project, opened ModifierMissingDetectorTest, went to the first test with violations, and added @Suppress("ComposeModifierMissing") in front of the first @composable annotation -- and when I run the test it shows that it's now suppressed the warning. I also used @android.annotation.SuppressLint("ComposeModifierMissing") and that worked too.

(By the way, in that codebase I see this --
// This mode is irrelevant to our test and totally untestable with stringy outputs
override val skipTestModes: Array =
arrayOf(TestMode.PARENTHESIZED, TestMode.SUPPRESSIBLE, TestMode.TYPE_ALIAS)
I removed TestMode.SUPPRESSIBLE and it seems to work fine here. I don't really understand the comment about "totally untestable with stringy outputs".)

Thanks for looking into it. How likely is that related to the test harness or detector implementation? I skimmed the implementation and nothing stuck out to me as obviously wrong.

Here's a repro: https://github.com/jzbrooks/SuppressLintWoe

Screenshot 2024-01-10 at 9 01 25 AM

Thanks for the reproduce case! I debugged this -- and discovered that this was fixed back in August. Basically, this lint check passes in the Kotlin PSI element as the context location (used for suppress directive lookup) instead of the UAST element, and that wasn't handled right (until August). If you update to 8.3.0-beta01 or later it should work.

Great. Thanks!

Thanks for the update @tnorbye & the additional comment no-inspection fix, and @jzbrooks for bringing this up again and providing a repro to get it fixed!

Awesome! Thanks all for the discussion here.

(By the way, in that codebase I see this --
// This mode is irrelevant to our test and totally untestable with stringy outputs
override val skipTestModes: Array =
arrayOf(TestMode.PARENTHESIZED, TestMode.SUPPRESSIBLE, TestMode.TYPE_ALIAS)
I removed TestMode.SUPPRESSIBLE and it seems to work fine here. I don't really understand the comment about "totally untestable with stringy outputs".)

I believe this was copied over from some internal lints, and predate knowledge of lint tests' ability to specify a specific test mode when asserting error/warning strings :). I'm slowly removing all these in #209