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 1
1
# Changelog
2
+
3
+ ## [ 2.0.1]
4
+
5
+ - Versions and gradle update
6
+ - Excluded http://schemas.android.com/tools from validations
7
+
2
8
---
3
9
4
10
## [ 2.0.0]
5
11
6
12
- 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
+
7
14
---
8
15
9
16
## [ 1.0.0]
Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ object AndroidConstants {
9
9
}
10
10
11
11
object 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 "
14
14
const val bintray_plugin_version = " 1.8.5"
15
15
16
16
const val bintray_version = " 1.8.5"
17
17
const val dokka_version = " 1.4.0"
18
18
19
19
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 "
21
21
// If the Gradle plugin version is X.Y.Z, then the Lint library version is X+23.Y.Z.
22
22
}
23
23
Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ class ColorResourceInXml : ResourceXmlDetector() {
18
18
}
19
19
20
20
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/ " )) ) {
24
24
reportUsage(context, attribute)
25
25
}
26
26
}
@@ -45,7 +45,10 @@ class ColorResourceInXml : ResourceXmlDetector() {
45
45
priority = 7 ,
46
46
severity = Severity .WARNING ,
47
47
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
+ )
49
52
)
50
53
}
51
54
}
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ class DirectColorInXml : ResourceXmlDetector() {
15
15
}
16
16
17
17
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(" #" )) {
19
20
reportUsage(context, attribute)
20
21
}
21
22
}
Original file line number Diff line number Diff line change @@ -86,6 +86,27 @@ class ColorResourceInXmlTest {
86
86
.expectClean()
87
87
}
88
88
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
+
89
110
@Test
90
111
fun cleanTestWithAttribute () {
91
112
val input = """
Original file line number Diff line number Diff line change @@ -35,4 +35,25 @@ class DirectColorInXmlTest {
35
35
.expect(output)
36
36
.expectWarningCount(1 )
37
37
}
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
+ }
38
59
}
Original file line number Diff line number Diff line change 1
1
distributionBase =GRADLE_USER_HOME
2
2
distributionPath =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
4
4
zipStoreBase =GRADLE_USER_HOME
5
5
zipStorePath =wrapper/dists
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<androidx .constraintlayout.widget.ConstraintLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3
3
xmlns : app =" http://schemas.android.com/apk/res-auto"
4
- xmlns : tools =" http://schemas.android.com/tools"
5
4
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" >
7
8
8
9
<com .google.android.material.button.MaterialButton
9
10
android : id =" @+id/btn1"
Original file line number Diff line number Diff line change 1
1
artifact =styling-lint
2
2
bintrayName =AndroidStyling-LintRules
3
- libraryVersion =2.0.0
3
+ libraryVersion =2.0.1
You can’t perform that action at this time.
0 commit comments