Skip to content

Commit

Permalink
Removed http://schemas.android.com/tools from validations
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhE committed Dec 15, 2020
1 parent 0dd3b1e commit 401cb9e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Changelog

## [2.0.1]

- Versions and gradle update
- Excluded http://schemas.android.com/tools from validations

---

## [2.0.0]

- Uses lintPublish, this way you just have to import styling-lint as a gradle dependency and checks will be automatically included in you project

---

## [1.0.0]
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/java/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object AndroidConstants {
}

object Versions {
const val build_gradle_version = "4.1.0-alpha02"
const val kotlin_gradle_plugin_version = "1.4.0"
const val build_gradle_version = "4.1.1"
const val kotlin_gradle_plugin_version = "1.4.21"
const val bintray_plugin_version = "1.8.5"

const val bintray_version = "1.8.5"
const val dokka_version = "1.4.0"

const val kotlin_stdlib_version = "1.4.0"
const val lint_version = "27.1.0-alpha02"
const val lint_version = "27.1.1"
//If the Gradle plugin version is X.Y.Z, then the Lint library version is X+23.Y.Z.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ColorResourceInXml : ResourceXmlDetector() {
}

override fun visitAttribute(context: XmlContext, attribute: Attr) {
if (attribute.value != "@android:color/transparent" &&
(attribute.value.startsWith("@color/") || (attribute.value.startsWith("@android:color/")))
) {
val ignore = attribute.namespaceURI == "http://schemas.android.com/tools"
|| attribute.value == "@android:color/transparent"
if (ignore.not() && (attribute.value.startsWith("@color/") || attribute.value.startsWith("@android:color/"))) {
reportUsage(context, attribute)
}
}
Expand All @@ -45,7 +45,10 @@ class ColorResourceInXml : ResourceXmlDetector() {
priority = 7,
severity = Severity.WARNING,
androidSpecific = true,
implementation = Implementation(ColorResourceInXml::class.java, Scope.RESOURCE_FILE_SCOPE)
implementation = Implementation(
ColorResourceInXml::class.java,
Scope.RESOURCE_FILE_SCOPE
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class DirectColorInXml : ResourceXmlDetector() {
}

override fun visitAttribute(context: XmlContext, attribute: Attr) {
if (attribute.value.startsWith("#")) {
val ignore = attribute.namespaceURI == "http://schemas.android.com/tools"
if (ignore.not() && attribute.value.startsWith("#")) {
reportUsage(context, attribute)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ class ColorResourceInXmlTest {
.expectClean()
}

@Test
fun ignoringTools() {
val input = """
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="@android:color/white"/>
"""
.trimIndent()

TestLintTask.lint()
.files(TestFiles.xml("res/layout/test_layout.xml", input).indented())
.issues(ColorResourceInXml.ISSUE)
.run()
.expectClean()
}

@Test
fun cleanTestWithAttribute() {
val input = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,25 @@ class DirectColorInXmlTest {
.expect(output)
.expectWarningCount(1)
}

@Test
fun ignoringTools() {
val input = """
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:background="@android:color/white"/>
"""
.trimIndent()

TestLintTask.lint()
.files(TestFiles.xml("res/layout/test_layout.xml", input).indented())
.issues(ColorResourceInXml.ISSUE)
.run()
.expectClean()
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 3 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:background="@android:color/white">

<com.google.android.material.button.MaterialButton
android:id="@+id/btn1"
Expand Down
2 changes: 1 addition & 1 deletion styling-lint/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
artifact=styling-lint
bintrayName=AndroidStyling-LintRules
libraryVersion=2.0.0
libraryVersion=2.0.1

0 comments on commit 401cb9e

Please sign in to comment.