Skip to content

Commit bfbb787

Browse files
authored
Merge pull request #60 from tnorbye/snapshot8
Update lint documentation snapshot
2 parents 895b05c + f9d440d commit bfbb787

File tree

106 files changed

+4304
-1302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+4304
-1302
lines changed

docs/api-guide.html

+72-96
Large diffs are not rendered by default.

docs/api-guide/annotations.md.html

+12-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
enforce. There are many examples of these, along with existing lint
77
checks:
88

9-
* `@VisibleForTesting`: this private API should only be accessed
10-
from outside this package from unit tests
9+
* `@VisibleForTesting`: this API is considered private, and has been
10+
exposed only for unit testing purposes
1111
* `@CheckResult`: anyone calling this method is expected to do
1212
something with the return value
1313
* `@CallSuper`: anyone overriding this method must also invoke `super`
@@ -190,10 +190,11 @@
190190
Note also that this would have worked if the annotation had been
191191
inherited from a super method instead of being explicitly set here.
192192

193-
Lint uses this mechanism for example for its resource type lint check
194-
which makes sure that if a method has been annotated with say
195-
`@DrawableRes`, that any return values are not of some incompatible
196-
esource type (such as `@StringRes`).
193+
One usage of this mechanism in Lint is the enforcement of return values
194+
in methods. For example, if a method has been marked with
195+
`@DrawableRes`, Lint will make sure that the returned value of that
196+
method will not be of an incompatible resource type (such as
197+
`@StringRes`).
197198

198199
### Handling Usage Types
199200

@@ -393,11 +394,12 @@
393394
deliberately supporting the operation, not just from tests. If
394395
annotations were always inherited, you would have to create some sort
395396
of annotation to "revert" the semantics, e.g.
396-
`@VisibleNotJustForTesting`, which would be ... anoying.
397+
`@VisibleNotJustForTesting`, which would require a lot of noisy
398+
annotations.
397399

398-
Lint let's you choose what the semantics are for each annotation. For
399-
example, the lint check which enforces the `@VisibleForTesting` and
400-
`@RestrictTo` annotations handles it like this:
400+
Lint lets you specify the inheritance behavior of individual
401+
annotations. For example, the lint check which enforces the
402+
`@VisibleForTesting` and `@RestrictTo` annotations handles it like this:
401403

402404
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin
403405
override fun inheritAnnotation(annotation: String): Boolean {

docs/api-guide/changes.md.html

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
**7.1**
99

10+
* Lint now bundles IntelliJ version 2021.1 and Kotlin compiler version 1.5.30.
11+
You may see minor API changes in these dependencies. For example,
12+
the Kotlin UAST class `KotlinUMethod` changed packages from
13+
`org.jetbrains.uast.kotlin.declarations` to `org.jetbrains.uast.kotlin`.
14+
1015
* The default behaviour of ResourceXmlDetector will change.
1116
It will skip res/raw folder and you have to override appliesTo method
1217
if you want your Lint checks to run there.
@@ -101,15 +106,7 @@
101106
* Partial analysis. Lint's architecture has changed to support better
102107
scalability across large projects, where module results can be
103108
cached, etc. See the api-guide's dedicated chapter for more details.
104-
It is enabled by default starting in AGP 7.0.0-alpha13, but you can
105-
disable it by adding
106-
107-
`android.enableParallelLint=false`
108-
109-
to your `gradle.properties` file. If you want to debug your lint check
110-
you may want to also set
111-
112-
`android.experimental.runLintInProcess=true`
109+
It is enabled by default starting in AGP 7.0.0-alpha13.
113110

114111
* Issue registration now takes an optional `Vendor` property, where you
115112
can specify information about which company or team provided this

docs/api-guide/unit-testing.md.html

+28-37
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@
108108
are a number of different types of test source files, such as for
109109
Kotlin files, manifest files, icons, property files, and so on.
110110

111-
Using test file descriptors like this has a number of advantages
112-
over the traditional approach of checking in test files as sources:
111+
Using test file descriptors like this to **describe** an input file has
112+
a number of advantages over the traditional approach of checking in
113+
test files as sources:
113114

114115
* Everything is kept together, so it's easier to look at a test and see
115116
what it analyzes and what the expected results are. This is
116117
particularly important for complex lint checks which test a lot of
117118
scenarios. As of this writing, `ApiDetectorTest` has 157 individual
118119
unit tests.
119120

121+
![Multiple test files shown inline](nested-test-files.png)
122+
120123
* Lint can provide a DSL to construct test files easily. For example,
121124
`projectProperties().compileSdk(17)` and
122125
`manifest().minSdk(5).targetSdk(17)` construct a `project.properties`
@@ -136,14 +139,19 @@
136139
code and figure out what the class file should be named and where to
137140
place it.
138141

139-
* We can easily “parameterize” our test files. For example, if you
140-
want to run your unit test against a 100K json file, you can
141-
construct it programmatically; you don't have to check one in.
142+
* We can easily “parameterize” our test files. For example, if you want
143+
to run your unit test against a 100K json file, you can construct it
144+
programmatically; you don't have to check one in. As another example
145+
you can programmatically create a number of repetitive scenarios.
146+
147+
* Since test sources often (deliberately!) have errors in them (which
148+
is relevant when lint is unning on the fly inside the IDE editor),
149+
this sometimes causes problems with the tooling; for example, some
150+
code review tools will flag “disallowed” constructs or things like
151+
tabs or trailing spaces, which may be deliberate in a lint unit test.
142152

143-
* Since test sources often (deliberately!) have errors in them, this
144-
sometimes causes problems with the tooling; for example, some code
145-
review tools will flag “disallowed” constructs or things like tabs or
146-
trailing spaces, which may be deliberate in a lint unit test.
153+
* You can test running in single-file mode, which is how lint is run
154+
on the fly in the editor.
147155

148156
* Lint originally checked in test sources as individual files.
149157
Unfortunately over time, source files ended up getting reused by
@@ -157,6 +165,12 @@
157165

158166
![Screenshot of nested highlighting](nested-syntax-highlighting.png)
159167

168+
* Finally, but most importantly, with the descriptors of your test
169+
scenarios, lint can re-run your tests under a number of different
170+
scenarios, including modifying your source files and project layout.
171+
This concept is documented in more detail in the [test
172+
modes](test-modes.md.html) chapter.
173+
160174
## Trimming indents?
161175

162176
Notice how in the above Kotlin unit tests we used raw strings, **and**
@@ -303,7 +317,7 @@
303317

304318
Here's an example of a test failure for an unresolved import:
305319

306-
```
320+
```text
307321
java.lang.IllegalStateException:
308322
app/src/com/example/MyDiffUtilCallbackJava.java:4: Error:
309323
Couldn't resolve this import [LintError]
@@ -375,6 +389,10 @@
375389
files (since a single source file can create multiple class files, and
376390
for Kotlin, some META-INF data).
377391

392+
Here's an example of a lint test which is using `bytecode(...)` to
393+
describe binary files:
394+
[](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/client/api/JarFileIssueRegistryTest.kt?q=testNewerLintBroken)
395+
378396
Initially, you just specify the sources, and when no binary data
379397
has been provided, lint will instead attempt to compile the sources
380398
and emit the full test file registration.
@@ -384,33 +402,6 @@
384402
project it will only provide the binaries, not the sources, for
385403
upstream modules.)
386404

387-
## Test Modes
388-
389-
"Describing” your source inputs using `TestFile` objects like this
390-
instead of just checking in your test files as real `.kt` and `.java`
391-
has a number of advantages:
392-
393-
* It's really easy to see what a test is doing; all the test files are
394-
placed right next to each other, with full syntax highlighting if you
395-
open the test cases in IntelliJ; example:
396-
397-
![Figure [screen]: Nested syntax highlighting](nested-test-files.png)
398-
399-
* You can test handling broken sources (which is relevant when lint is
400-
running on the fly inside the IDE editor).
401-
402-
* You can test running in single-file mode, which is how lint is run
403-
on the fly in the editor.
404-
405-
* You can create test files programmatically if you want to cover
406-
a number of repetitive scenarios
407-
408-
* Finally, but most importantly, with the descriptors of your test
409-
scenarios, lint can re-run your tests under a number of different
410-
scenarios, including modifying your source files and project layout.
411-
This concept is documented in more detail in the [test
412-
modes](test-modes.md.html) chapter.
413-
414405
## My Detector Isn't Invoked From a Test!
415406

416407
One common question we hear is

docs/checks/AllowBackup.md.html

+4-152
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,7 @@
11
<meta charset="utf-8">
2-
(#) AllowBackup/FullBackupContent Problems
2+
(#) AllowBackup
33

4-
!!! WARNING: AllowBackup/FullBackupContent Problems
5-
This is a warning.
4+
The issue for this id has been deleted or marked obsolete and can now be
5+
ignored.
66

7-
Id
8-
: `AllowBackup`
9-
Summary
10-
: AllowBackup/FullBackupContent Problems
11-
Severity
12-
: Warning
13-
Category
14-
: Security
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-
: Manifest files
23-
Editing
24-
: This check runs on the fly in the IDE editor
25-
See
26-
: https://developer.android.com/guide/topics/data/autobackup
27-
See
28-
: https://developer.android.com/reference/android/R.attr.html#allowBackup
29-
Implementation
30-
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-master-dev:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/ManifestDetector.kt)
31-
Tests
32-
: [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-master-dev:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt)
33-
34-
The `allowBackup` attribute determines if an application's data can be
35-
backed up and restored. It is documented at
36-
https://developer.android.com/reference/android/R.attr.html#allowBackup
37-
38-
By default, this flag is set to `true` which means application data can
39-
be backed up and restored by the OS. Setting `allowBackup="false"` opts
40-
the application out of being backed up and so users can't restore data
41-
related to it when they go through the device setup wizard.
42-
43-
Allowing backups may have security consequences for an application.
44-
Currently `adb backup` allows users who have enabled USB debugging to
45-
copy application data off of the device. Once backed up, all application
46-
data can be read by the user. `adb restore` allows creation of
47-
application data from a source specified by the user. Following a
48-
restore, applications should not assume that the data, file permissions,
49-
and directory permissions were created by the application itself.
50-
51-
To fix this warning, decide whether your application should support
52-
backup, and explicitly set `android:allowBackup=(true|false)"`.
53-
54-
If not set to false, and if targeting API 23 or later, lint will also
55-
warn that you should set `android:fullBackupContent` or
56-
`android:fullBackupOnly` to configure auto backup.
57-
58-
!!! Tip
59-
This lint check has an associated quickfix available in the IDE.
60-
61-
(##) Example
62-
63-
Here is an example of lint warnings produced by this check:
64-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
65-
AndroidManifest.xml:8:Warning: Should explicitly set android:allowBackup
66-
to true or false (it's true by default, and that can have some security
67-
implications for the application's data) [AllowBackup]
68-
69-
&lt;application
70-
-----------
71-
72-
73-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74-
75-
Here is the source file referenced above:
76-
77-
`AndroidManifest.xml`:
78-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
79-
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
80-
package="test.bytecode"
81-
android:versionCode="1"
82-
android:versionName="1.0" &gt;
83-
84-
&lt;uses-sdk android:minSdkVersion="14" /&gt;
85-
86-
&lt;application
87-
android:icon="@drawable/ic_launcher"
88-
android:label="@string/app_name" &gt;
89-
&lt;/application&gt;
90-
91-
&lt;/manifest&gt;
92-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93-
94-
You can also visit the
95-
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-master-dev:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.kt)
96-
for the unit tests for this check to see additional scenarios.
97-
98-
The above example was automatically extracted from the first unit test
99-
found for this lint check, `ManifestDetector.testAllowBackup`.
100-
To report a problem with this extracted sample, visit
101-
https://issuetracker.google.com/issues/new?component=192708.
102-
103-
(##) Suppressing
104-
105-
You can suppress false positives using one of the following mechanisms:
106-
107-
* Adding the suppression attribute `tools:ignore="AllowBackup"` on the
108-
problematic XML element (or one of its enclosing elements). You may
109-
also need to add the following namespace declaration on the root
110-
element in the XML file if it's not already there:
111-
`xmlns:tools="http://schemas.android.com/tools"`.
112-
113-
```xml
114-
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
115-
&lt;manifest xmlns:tools="http://schemas.android.com/tools"&gt;
116-
...
117-
&lt;application tools:ignore="AllowBackup" .../&gt;
118-
...
119-
&lt;/manifest&gt;
120-
```
121-
122-
* Using a special `lint.xml` file in the source tree which turns off
123-
the check in that folder and any sub folder. A simple file might look
124-
like this:
125-
```xml
126-
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
127-
&lt;lint&gt;
128-
&lt;issue id="AllowBackup" severity="ignore" /&gt;
129-
&lt;/lint&gt;
130-
```
131-
Instead of `ignore` you can also change the severity here, for
132-
example from `error` to `warning`. You can find additional
133-
documentation on how to filter issues by path, regular expression and
134-
so on
135-
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).
136-
137-
* In Gradle projects, using the DSL syntax to configure lint. For
138-
example, you can use something like
139-
```gradle
140-
lintOptions {
141-
disable 'AllowBackup'
142-
}
143-
```
144-
In Android projects this should be nested inside an `android { }`
145-
block.
146-
147-
* For manual invocations of `lint`, using the `--ignore` flag:
148-
```
149-
$ lint --ignore AllowBackup ...`
150-
```
151-
152-
* Last, but not least, using baselines, as discussed
153-
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).
154-
155-
<!-- 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>
7+
(Additional metadata not available.)<!-- 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/AndroidGradlePluginVersion.md.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
Here is an example of lint warnings produced by this check:
4343
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
4444
build.gradle:7:Warning: A newer version of
45-
com.android.tools.build:gradle than 2.4.0-alpha3 is available:
46-
3.5.0-alpha10 [AndroidGradlePluginVersion]
45+
com.android.tools.build:gradle than 3.4.0-alpha3 is available:
46+
3.6.0-alpha01 [AndroidGradlePluginVersion]
4747

48-
classpath 'com.android.tools.build:gradle:2.4.0-alpha3'
48+
classpath 'com.android.tools.build:gradle:3.4.0-alpha3'
4949
-------------------------------------------------------
5050

5151

@@ -61,7 +61,7 @@
6161
jcenter()
6262
}
6363
dependencies {
64-
classpath 'com.android.tools.build:gradle:2.4.0-alpha3'
64+
classpath 'com.android.tools.build:gradle:3.4.0-alpha3'
6565
}
6666
}
6767
dependencies {

0 commit comments

Comments
 (0)