And*_*lov 6 xml android lint android-studio
我有我的自定义 lint,它检查 XML 文件的十六进制颜色使用情况。
当我运行时它完美地工作
./gradlew myapp:lint
Run Code Online (Sandbox Code Playgroud)
但它没有突出问题的地方。甚至更多 - Analyze -> Inspect Code不给我结果,只返回
未发现可疑代码。
源代码:
class XmlColorsDetector : ResourceXmlDetector() {
companion object {
val ISSUE: Issue = Issue.create(
id = "CustomColorsXml",
briefDescription = "Custom colors detector",
explanation = "Use only theme colors, in other case our themes behaviour will not work properly",
category = Category.CORRECTNESS,
priority = 6,
severity = Severity.ERROR,
implementation = Implementation(
XmlColorsDetector::class.java,
Scope.RESOURCE_FILE_SCOPE
)
)
}
override fun getApplicableAttributes(): Collection<String>? {
return listOf("color", "textColor", "background")
}
override fun getApplicableElements(): Collection<String>? {
return listOf("color")
}
override fun visitAttribute(context: XmlContext, attribute: Attr) {
if (attribute.textContent.startsWith("#") && !context.file.path.containsExcludes()) {
println("uri" + context.file.path)
context.report(ISSUE, context.getLocation(attribute), "You can not use hardcoded colors")
}
}
private fun String.containsExcludes(): Boolean {
val excludes = listOf("/color", "/drawable")
excludes.forEach {
if (this.contains(it))
return true
}
return false
}
}
Run Code Online (Sandbox Code Playgroud)
我试过了,LintFix
但没有任何改变。
如何在 Android Studio 中获得适当的亮点?
归档时间: |
|
查看次数: |
240 次 |
最近记录: |