Ensuring code-correctness with custom lint checks
summary
A small custom lint module named checks detects unit test classes that have methods annotated with @TestId but lack the class-level @TestReporter, reports an error on the class in the IDE, and offers a quickfix that inserts @TestReporter. Implementation uses Lint Issue + IssueRegistry, a SourceCodeScanner with UElementHandler and JavaContext, unit tests with annotation stubs to assert one error, and a lint.xml rule to ignore androidTest sources. The rule runs in the IDE and via the lint CLI and works as expected, surfacing and auto-fixing missing annotations.
AI-written summary · about
chapters (12)
- 0:00Introduction to talk
- 0:48What are lint checks
- 2:58Problem with test reporter
- 3:41Creating a lint issue
- 5:03Writing the detector
- 6:07Verifying annotations
- 8:55Testing the lint check
- 10:39Making lint visible to IDE
- 11:46Quick demo of the check
- 12:48Handling Android tests
- 14:12Resources and references
- 16:19Closing and Q&A
related talks
19mThe power of custom lint checks
21mMastering Code Quality: A Deep Dive into Custom Linting for Android Developers
44mLint. What, Why, How?
29mMaking rules with Lint
27mBuild an Android Lint in 25 Minutes
46mLint for Life: Your Customizable Guard On the Go
24mImprove your code with Lint checks for Kotlin
23mConsistent Design with Custom Lint Checks
