Skip to content

Commit 6cf68da

Browse files
committed
Update docs to include recent lint checks and formatting fixes
1 parent f3c96a6 commit 6cf68da

25 files changed

+873
-19
lines changed

docs/checks/AnnotationProcessorOnCompilePath.md.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
This dependency is identified as an annotation processor. Consider
3333
adding it to the processor path using `annotationProcessor` instead of
34-
including it to the
35-
compile path.
34+
including it to the compile path.
3635

3736
!!! Tip
3837
This lint check has an associated quickfix available in the IDE.

docs/checks/ApplySharedPref.md.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131

132132
}
133133
}
134-
135134
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136135

137136
You can also visit the

docs/checks/BackButton.md.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
user to navigate up the application's hierarchy. Instead, Android uses
4040
the main action bar's app icon for hierarchical navigation and the
4141
navigation bar's back button for temporal navigation."
42+
4243
This check is not very sophisticated (it just looks for buttons with the
4344
label "Back"), so it is disabled by default to not trigger on common
4445
scenarios like pairs of Back/Next buttons to paginate through screens.

docs/checks/BrokenIterator.md.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545

4646
Instead of `c.stream()` or `c.parallelStream()`, use
4747
`java.util.stream.StreamSupport.stream(spliterator, false)` to construct
48-
a
49-
(nonparallel) Stream from such a `Spliterator`.
48+
a (nonparallel) Stream from such a `Spliterator`.
5049

5150
**For Vector:**
5251

docs/checks/CommitPrefEdits.md.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136

137137
}
138138
}
139-
140139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141140

142141
You can also visit the
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<meta charset="utf-8">
2+
(#) Using a method deprecated in earlier SDK
3+
4+
!!! WARNING: Using a method deprecated in earlier SDK
5+
This is a warning.
6+
7+
Id
8+
: `DeprecatedSinceApi`
9+
Summary
10+
: Using a method deprecated in earlier SDK
11+
Severity
12+
: Warning
13+
Category
14+
: Correctness
15+
Platform
16+
: Android
17+
Vendor
18+
: Android Open Source Project
19+
Feedback
20+
: https://issuetracker.google.com/issues/new?component=192708
21+
Affects
22+
: Kotlin and Java files
23+
Editing
24+
: This check runs on the fly in the IDE editor
25+
Implementation
26+
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/DeprecatedSinceApiDetector.kt)
27+
Tests
28+
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DeprecatedSinceApiDetectorTest.kt)
29+
Copyright Year
30+
: 2022
31+
32+
Some backport methods are only necessary until a specific version of
33+
Android. These have been annotated with `@DeprecatedSinceApi`,
34+
specifying the relevant API level and replacement suggestions. Calling
35+
these methods when the `minSdkVersion` is already at the deprecated API
36+
level or above is unnecessary.
37+
38+
(##) Example
39+
40+
Here is an example of lint warnings produced by this check:
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
42+
src/test/pkg/Api.kt:26:Warning: This method is deprecated as of API
43+
level 25 [DeprecatedSinceApi]
44+
45+
api.someMethod2(0) // WARN 1
46+
------------------
47+
48+
49+
src/test/pkg/Api.kt:27:Warning: This method is deprecated as of API
50+
level 30; Use AlarmManager.notify instead [DeprecatedSinceApi]
51+
52+
api.someMethod3(0) // WARN 2
53+
------------------
54+
55+
56+
src/test/pkg/Api.kt:28:Warning: This field is deprecated as of API level
57+
30 [DeprecatedSinceApi]
58+
59+
val c = MY_CONSTANT // WARN 3
60+
-----------
61+
62+
63+
src/test/pkg/Api.kt:29:Warning: This class is deprecated as of API level
64+
28 [DeprecatedSinceApi]
65+
66+
api2.someMethod1(0) // WARN 4
67+
-------------------
68+
69+
70+
src/test/pkg/Api.kt:30:Warning: This method is deprecated as of API
71+
level 30 [DeprecatedSinceApi]
72+
73+
api2.someMethod2(0) // WARN 5
74+
-------------------
75+
76+
77+
src/test/pkg/Api.kt:31:Warning: This class is deprecated as of API level
78+
28 [DeprecatedSinceApi]
79+
80+
val clz = Api2::class.java // WARN 6
81+
-----------
82+
83+
84+
src/test/pkg/Api.kt:32:Warning: This method is deprecated as of API
85+
level 25 [DeprecatedSinceApi]
86+
87+
println(api::someMethod2) // WARN 7
88+
----------------
89+
90+
91+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92+
93+
Here is the source file referenced above:
94+
95+
`src/test/pkg/Api.kt`:
96+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
97+
package test.pkg
98+
import androidx.annotation.DeprecatedSinceApi
99+
100+
class Api {
101+
@DeprecatedSinceApi(api = 21)
102+
fun someMethod1(arg: Int) { }
103+
@DeprecatedSinceApi(api = 25)
104+
fun someMethod2(arg: Int) { }
105+
@DeprecatedSinceApi(api = 30, message = "Use AlarmManager.notify instead")
106+
fun someMethod3(arg: Int) { }
107+
}
108+
109+
@DeprecatedSinceApi(api = 28)
110+
class Api2 {
111+
fun someMethod1(arg: Int) { }
112+
@DeprecatedSinceApi(api = 30)
113+
fun someMethod2(arg: Int) { }
114+
}
115+
116+
@DeprecatedSinceApi(30)
117+
const val MY_CONSTANT = "test"
118+
119+
class Test {
120+
fun test(api: Api, api2: Api2) {
121+
api.someMethod1(0) // OK
122+
api.someMethod2(0) // WARN 1
123+
api.someMethod3(0) // WARN 2
124+
val c = MY_CONSTANT // WARN 3
125+
api2.someMethod1(0) // WARN 4
126+
api2.someMethod2(0) // WARN 5
127+
val clz = Api2::class.java // WARN 6
128+
println(api::someMethod2) // WARN 7
129+
}
130+
}
131+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
You can also visit the
134+
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/DeprecatedSinceApiDetectorTest.kt)
135+
for the unit tests for this check to see additional scenarios.
136+
137+
(##) Suppressing
138+
139+
You can suppress false positives using one of the following mechanisms:
140+
141+
* Using a suppression annotation like this on the enclosing
142+
element:
143+
144+
```kt
145+
// Kotlin
146+
@Suppress("DeprecatedSinceApi")
147+
fun method() {
148+
problematicStatement()
149+
}
150+
```
151+
152+
or
153+
154+
```java
155+
// Java
156+
@SuppressWarnings("DeprecatedSinceApi")
157+
void method() {
158+
problematicStatement();
159+
}
160+
```
161+
162+
* Using a suppression comment like this on the line above:
163+
164+
```kt
165+
//noinspection DeprecatedSinceApi
166+
problematicStatement()
167+
```
168+
169+
* Using a special `lint.xml` file in the source tree which turns off
170+
the check in that folder and any sub folder. A simple file might look
171+
like this:
172+
```xml
173+
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
174+
&lt;lint&gt;
175+
&lt;issue id="DeprecatedSinceApi" severity="ignore" /&gt;
176+
&lt;/lint&gt;
177+
```
178+
Instead of `ignore` you can also change the severity here, for
179+
example from `error` to `warning`. You can find additional
180+
documentation on how to filter issues by path, regular expression and
181+
so on
182+
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).
183+
184+
* In Gradle projects, using the DSL syntax to configure lint. For
185+
example, you can use something like
186+
```gradle
187+
lintOptions {
188+
disable 'DeprecatedSinceApi'
189+
}
190+
```
191+
In Android projects this should be nested inside an `android { }`
192+
block.
193+
194+
* For manual invocations of `lint`, using the `--ignore` flag:
195+
```
196+
$ lint --ignore DeprecatedSinceApi ...`
197+
```
198+
199+
* Last, but not least, using baselines, as discussed
200+
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).
201+
202+
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

docs/checks/EmptySuperCall.md.html

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<meta charset="utf-8">
2+
(#) Calling an empty super method
3+
4+
!!! WARNING: Calling an empty super method
5+
This is a warning.
6+
7+
Id
8+
: `EmptySuperCall`
9+
Summary
10+
: Calling an empty super method
11+
Severity
12+
: Warning
13+
Category
14+
: Correctness
15+
Platform
16+
: Any
17+
Vendor
18+
: Android Open Source Project
19+
Feedback
20+
: https://issuetracker.google.com/issues/new?component=192708
21+
Affects
22+
: Kotlin and Java files
23+
Editing
24+
: This check runs on the fly in the IDE editor
25+
Implementation
26+
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/EmptySuperDetector.kt)
27+
Tests
28+
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/EmptySuperDetectorTest.kt)
29+
Copyright Year
30+
: 2022
31+
32+
For methods annotated with `@EmptySuper`, overriding methods should not
33+
also call the super implementation, either because it is empty, or
34+
perhaps it contains code not intended to be run when the method is
35+
overridden.
36+
37+
(##) Example
38+
39+
Here is an example of lint warnings produced by this check:
40+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
41+
src/ParentClass.kt:22:Warning: No need to call super.someOtherMethod;
42+
the super method is defined to be empty [EmptySuperCall]
43+
44+
super.someOtherMethod(arg) // ERROR
45+
---------------
46+
47+
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
50+
Here is the source file referenced above:
51+
52+
`src/ParentClass.kt`:
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
54+
import androidx.annotation.EmptySuper
55+
56+
open class ParentClass {
57+
@EmptySuper
58+
open fun someMethod(arg: Int) {
59+
// ...
60+
}
61+
62+
@EmptySuper
63+
open fun someOtherMethod(arg: Int) {
64+
// ...
65+
}
66+
}
67+
68+
class MyClass : ParentClass() {
69+
override fun someMethod(arg: Int) {
70+
// Not calling the overridden (@EmptySuper) method.
71+
println(super.toString()) // but invoking other super methods is fine
72+
}
73+
74+
override fun someOtherMethod(arg: Int) {
75+
super.someOtherMethod(arg) // ERROR
76+
}
77+
}
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
80+
You can also visit the
81+
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/EmptySuperDetectorTest.kt)
82+
for the unit tests for this check to see additional scenarios.
83+
84+
(##) Suppressing
85+
86+
You can suppress false positives using one of the following mechanisms:
87+
88+
* Using a suppression annotation like this on the enclosing
89+
element:
90+
91+
```kt
92+
// Kotlin
93+
@Suppress("EmptySuperCall")
94+
fun method() {
95+
problematicStatement()
96+
}
97+
```
98+
99+
or
100+
101+
```java
102+
// Java
103+
@SuppressWarnings("EmptySuperCall")
104+
void method() {
105+
problematicStatement();
106+
}
107+
```
108+
109+
* Using a suppression comment like this on the line above:
110+
111+
```kt
112+
//noinspection EmptySuperCall
113+
problematicStatement()
114+
```
115+
116+
* Using a special `lint.xml` file in the source tree which turns off
117+
the check in that folder and any sub folder. A simple file might look
118+
like this:
119+
```xml
120+
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
121+
&lt;lint&gt;
122+
&lt;issue id="EmptySuperCall" severity="ignore" /&gt;
123+
&lt;/lint&gt;
124+
```
125+
Instead of `ignore` you can also change the severity here, for
126+
example from `error` to `warning`. You can find additional
127+
documentation on how to filter issues by path, regular expression and
128+
so on
129+
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).
130+
131+
* In Gradle projects, using the DSL syntax to configure lint. For
132+
example, you can use something like
133+
```gradle
134+
lintOptions {
135+
disable 'EmptySuperCall'
136+
}
137+
```
138+
In Android projects this should be nested inside an `android { }`
139+
block.
140+
141+
* For manual invocations of `lint`, using the `--ignore` flag:
142+
```
143+
$ lint --ignore EmptySuperCall ...`
144+
```
145+
146+
* Last, but not least, using baselines, as discussed
147+
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).
148+
149+
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>

0 commit comments

Comments
 (0)