How to suppress a lint warning in some code but not everywhere?

Viewed 89

I'm trying to suppress HardcodedStringLiteral in places that the string is a named code reference, not customer facing. Specifically, this is an issue with named Dagger injection.

If I have, for example,

class MyViewModel @Inject constructor(
    private val resourceRetriever: ResourceRetriever,
    @Named("thing_one") private val thingOne: BehaviorRelay<String>,
    @Named("thing_two") private val thingTwo: BehaviorRelay<String>,
    ...
)

I get HardcodedStringLiteral warnings on thing_one and thing_two. I could add @Suppress("HardCodedStringLiteral") to every @Named but there are hundreds of them through the project. I don't want to just suppress it at the file, class, or project level because I do care about other hardcoded string literals.

I was hoping to configure something (lint.xml, lint options in build.gradle, etc.) that basically says

<issue id="HardCodedStringLiteral">
    <ignore anything="@Named" />
</issue>

but can't figure out how to define anything="@Named".

0 Answers
Related