Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77b5b7c1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update lint OWNERS and README " into main

parents 5ff2bc8b f7c617d3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ mattgilbride@google.com
azharaa@google.com

per-file *CallingSettingsNonUserGetterMethods* = file:/packages/SettingsProvider/OWNERS
per-file *RegisterReceiverFlagDetector* = jacobhobbie@google.com

# Android lint in the Android platform maintainers
colefaust@google.com
+6 −82
Original line number Diff line number Diff line
# Android Lint Checks for AOSP

Custom Android Lint checks are written here to be executed against java modules
in AOSP. These checks are broken down into two subdirectories:

1. [Global Checks](#android-global-lint-checker)
2. [Framework Checks](#android-framework-lint-checker)

# [Android Global Lint Checker](./global)
Checks written here are executed for the entire tree. The `AndroidGlobalLintChecker`
build target produces a jar file that is included in the overall build output
(`AndroidGlobalLintChecker.jar`).  This file is then downloaded as a prebuilt under the
`prebuilts/cmdline-tools` subproject, and included by soong with all invocations of lint.

## How to add new global lint checks
1. Write your detector with its issues and put it into
   `global/checks/src/main/java/com/google/android/lint`.
2. Add your detector's issues into `AndroidGlobalIssueRegistry.kt`'s `issues`
   field.
3. Write unit tests for your detector in one file and put it into
   `global/checks/test/java/com/google/android/lint`.
4. Have your change reviewed and merged.  Once your change is merged,
   obtain a build number from a successful build that includes your change.
5. Run `prebuilts/cmdline-tools/update-android-global-lint-checker.sh
   <build_number>`. The script will create a commit that you can upload for
   approval to the `prebuilts/cmdline-tools` subproject.
   - *Tip*: Find a green build from [targets=aosp_arm64-trunk_staging-userdebug](https://android-build.corp.google.com/build_explorer/branch/git_main/?gridSize=20&targets=aosp_arm64-trunk_staging-userdebug&selectionType=MOST_RECENT_N_BUILDS&numBuilds=20&buildType=default) to match the update script.
6. Done! Your lint check should be applied in lint report builds across the
   entire tree!

# [Android Framework Lint Checker](./framework)

Checks written here are going to be executed for modules that opt in to those (e.g. any
@@ -58,11 +28,12 @@ java_library_static {
```
2. Run the following command to verify that the report is being correctly built:
```
m out/soong/.intermediates/frameworks/base/services/autofill/services.autofill/android_common/lint/lint-report.html
m services-autofill-lint
```
   Replace `services/autofill/` with the appropriate directory path and replace
   `services.autofill` with your module's name. After you run the command, the
   lint report can be found in the same path, i.e. `out/../lint-report.html`.
   Replace `services-autofil` with your module's name. After you run the command, the
   lint report can be found in the soong intermediates path corresponding to your
   module , i.e.
   `out/soong/.intermediates/frameworks/base/services/autofill/services.autofill/android_common/lint/lint-report.html`.

3. Now lint issues should appear on gerrit!

@@ -77,51 +48,4 @@ m out/soong/.intermediates/frameworks/base/services/autofill/services.autofill/a
  environment variable with the id of the lint. For example:
  `ANDROID_LINT_CHECK=UnusedTokenOfOriginalCallingIdentity m out/[...]/lint-report.html`

# How to apply automatic fixes suggested by lint

See [lint_fix](fix/README.md)

# Create or update a baseline

Baseline files can be used to silence known errors (and warnings) that are deemed to be safe. When
there is a lint-baseline.xml file in the root folder of the java library, soong will
automatically use it. You can override the file using lint properties too.

```
java_library {
    lint: {
        baseline_filename: "my-baseline.xml", // default: lint-baseline.xml;
    }
}
```

When using soong to create a lint report (as described above), it also creates a reference
baseline file. This contains all lint errors and warnings that were found. So the next time
you run lint, if you use this baseline file, there should be 0 findings.

After the previous invocation, you can find the baseline here:

```
out/soong/.intermediates/frameworks/base/services/autofill/services.autofill/android_common/lint/lint-baseline.xml
```

As noted above, this baseline file contains warnings too, which might be undesirable. For example,
CI tools might surface these warnings in code reviews. In order to create this file without
warnings, we need to pass another flag to lint: `--nowarn`. One option is to add the flag to your
Android.bp file and then run lint again:

```
  lint: {
    extra_check_modules: ["AndroidFrameworkLintChecker"],
    flags: ["--nowarn"],
  }
```

# Documentation

- [Android Lint Docs](https://googlesamples.github.io/android-custom-lint-rules/)
- [Lint Check Unit Testing](https://googlesamples.github.io/android-custom-lint-rules/api-guide/unit-testing.md.html)
- [Android Lint source files](https://source.corp.google.com/studio-main/tools/base/lint/libs/lint-api/src/main/java/com/android/tools/lint/)
- [PSI source files](https://github.com/JetBrains/intellij-community/tree/master/java/java-psi-api/src/com/intellij/psi)
- [UAST source files](https://upsource.jetbrains.com/idea-ce/structure/idea-ce-7b9b8cc138bbd90aec26433f82cd2c6838694003/uast/uast-common/src/org/jetbrains/uast)
- [IntelliJ plugin for viewing PSI tree of files](https://plugins.jetbrains.com/plugin/227-psiviewer)
  There are more notes and instructions available in the `//platform/tools/lint_checks` repo.