File tree Expand file tree Collapse file tree 9 files changed +66
-12
lines changed
main/java/com/github/guilhe/lint
test/java/com/github/guilhe/lint
sample/src/main/res/layout Expand file tree Collapse file tree 9 files changed +66
-12
lines changed Original file line number Diff line number Diff line change 11# Changelog
2+
3+ ## [ 2.0.1]
4+
5+ - Versions and gradle update
6+ - Excluded http://schemas.android.com/tools from validations
7+
28---
39
410## [ 2.0.0]
511
612- Uses lintPublish, this way you just have to import styling-lint as a gradle dependency and checks will be automatically included in you project
13+
714---
815
916## [ 1.0.0]
Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ object AndroidConstants {
99}
1010
1111object Versions {
12- const val build_gradle_version = " 4.1.0-alpha02 "
13- const val kotlin_gradle_plugin_version = " 1.4.0 "
12+ const val build_gradle_version = " 4.1.1 "
13+ const val kotlin_gradle_plugin_version = " 1.4.21 "
1414 const val bintray_plugin_version = " 1.8.5"
1515
1616 const val bintray_version = " 1.8.5"
1717 const val dokka_version = " 1.4.0"
1818
1919 const val kotlin_stdlib_version = " 1.4.0"
20- const val lint_version = " 27.1.0-alpha02 "
20+ const val lint_version = " 27.1.1 "
2121 // If the Gradle plugin version is X.Y.Z, then the Lint library version is X+23.Y.Z.
2222}
2323
Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ class ColorResourceInXml : ResourceXmlDetector() {
1818 }
1919
2020 override fun visitAttribute (context : XmlContext , attribute : Attr ) {
21- if ( attribute.value != " @android:color/transparent " &&
22- (attribute.value.startsWith( " @color/ " ) || ( attribute.value.startsWith( " @android:color/" )))
23- ) {
21+ val ignore = attribute.namespaceURI == " http://schemas.android.com/tools "
22+ || attribute.value == " @android:color/transparent "
23+ if (ignore. not () && (attribute.value.startsWith( " @color/ " ) || attribute.value.startsWith( " @android:color/ " )) ) {
2424 reportUsage(context, attribute)
2525 }
2626 }
@@ -45,7 +45,10 @@ class ColorResourceInXml : ResourceXmlDetector() {
4545 priority = 7 ,
4646 severity = Severity .WARNING ,
4747 androidSpecific = true ,
48- implementation = Implementation (ColorResourceInXml ::class .java, Scope .RESOURCE_FILE_SCOPE )
48+ implementation = Implementation (
49+ ColorResourceInXml ::class .java,
50+ Scope .RESOURCE_FILE_SCOPE
51+ )
4952 )
5053 }
5154}
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ class DirectColorInXml : ResourceXmlDetector() {
1515 }
1616
1717 override fun visitAttribute (context : XmlContext , attribute : Attr ) {
18- if (attribute.value.startsWith(" #" )) {
18+ val ignore = attribute.namespaceURI == " http://schemas.android.com/tools"
19+ if (ignore.not () && attribute.value.startsWith(" #" )) {
1920 reportUsage(context, attribute)
2021 }
2122 }
Original file line number Diff line number Diff line change @@ -86,6 +86,27 @@ class ColorResourceInXmlTest {
8686 .expectClean()
8787 }
8888
89+ @Test
90+ fun ignoringTools () {
91+ val input = """
92+ <?xml version="1.0" encoding="utf-8"?>
93+ <androidx.constraintlayout.widget.ConstraintLayout
94+ xmlns:android="http://schemas.android.com/apk/res/android"
95+ xmlns:app="http://schemas.android.com/apk/res-auto"
96+ xmlns:tools="http://schemas.android.com/tools"
97+ android:layout_width="match_parent"
98+ android:layout_height="match_parent"
99+ tools:background="@android:color/white"/>
100+ """
101+ .trimIndent()
102+
103+ TestLintTask .lint()
104+ .files(TestFiles .xml(" res/layout/test_layout.xml" , input).indented())
105+ .issues(ColorResourceInXml .ISSUE )
106+ .run ()
107+ .expectClean()
108+ }
109+
89110 @Test
90111 fun cleanTestWithAttribute () {
91112 val input = """
Original file line number Diff line number Diff line change @@ -35,4 +35,25 @@ class DirectColorInXmlTest {
3535 .expect(output)
3636 .expectWarningCount(1 )
3737 }
38+
39+ @Test
40+ fun ignoringTools () {
41+ val input = """
42+ <?xml version="1.0" encoding="utf-8"?>
43+ <androidx.constraintlayout.widget.ConstraintLayout
44+ xmlns:android="http://schemas.android.com/apk/res/android"
45+ xmlns:app="http://schemas.android.com/apk/res-auto"
46+ xmlns:custom="http://schemas.android.com/tools"
47+ android:layout_width="match_parent"
48+ android:layout_height="match_parent"
49+ custom:background="@android:color/white"/>
50+ """
51+ .trimIndent()
52+
53+ TestLintTask .lint()
54+ .files(TestFiles .xml(" res/layout/test_layout.xml" , input).indented())
55+ .issues(ColorResourceInXml .ISSUE )
56+ .run ()
57+ .expectClean()
58+ }
3859}
Original file line number Diff line number Diff line change 11distributionBase =GRADLE_USER_HOME
22distributionPath =wrapper/dists
3- distributionUrl =https\://services.gradle.org/distributions/gradle-6.6 .1-all.zip
3+ distributionUrl =https\://services.gradle.org/distributions/gradle-6.7 .1-all.zip
44zipStoreBase =GRADLE_USER_HOME
55zipStorePath =wrapper/dists
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" utf-8" ?>
22<androidx .constraintlayout.widget.ConstraintLayout xmlns : android =" http://schemas.android.com/apk/res/android"
33 xmlns : app =" http://schemas.android.com/apk/res-auto"
4- xmlns : tools =" http://schemas.android.com/tools"
54 android : layout_width =" match_parent"
6- android : layout_height =" match_parent" >
5+ android : layout_height =" match_parent"
6+ xmlns : tools =" http://schemas.android.com/tools"
7+ tools : background =" @android:color/white" >
78
89 <com .google.android.material.button.MaterialButton
910 android : id =" @+id/btn1"
Original file line number Diff line number Diff line change 11artifact =styling-lint
22bintrayName =AndroidStyling-LintRules
3- libraryVersion =2.0.0
3+ libraryVersion =2.0.1
You can’t perform that action at this time.
0 commit comments