Created
July 17, 2020 13:26
-
-
Save ataulm/3ebeb00919245a27de2bd6a931eee6af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class StyleAttrUsesThemeDetector : ResourceXmlDetector() { | |
companion object { | |
val ISSUE = createErrorThemesAndStylesIssue(StyleAttrUsesThemeDetector::class, Scope.RESOURCE_FILE_SCOPE) | |
} | |
override fun appliesTo(folderType: ResourceFolderType) = folderType == ResourceFolderType.LAYOUT | |
override fun getApplicableAttributes(): Collection<String> = XmlScannerConstants.ALL | |
override fun visitAttribute(context: XmlContext, attribute: Attr) { | |
if (attribute.name != "style") { | |
return | |
} | |
ResourceUrl.parse(attribute.nodeValue)?.let { resourceUrl -> | |
if (resourceUrl.name.contains("Theme")) { | |
reportIssue(context, attribute) | |
} | |
} | |
} | |
private fun reportIssue(context: XmlContext, attribute: Attr) = context.report( | |
issue = ISSUE, | |
scope = attribute, | |
location = context.getValueLocation(attribute), | |
message = "`style` should not reference theme resources." | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment