From c759d2716d9377df27437587bcd7860fa9ead85f Mon Sep 17 00:00:00 2001 From: Fuad Balashov Date: Sun, 11 Feb 2018 10:28:08 -0500 Subject: [PATCH 1/4] Spelling Corrections --- 2_lint_api_basics/README.md | 12 ++++++------ 4_detectors/README.md | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/2_lint_api_basics/README.md b/2_lint_api_basics/README.md index 7443a41..dab5448 100644 --- a/2_lint_api_basics/README.md +++ b/2_lint_api_basics/README.md @@ -7,16 +7,16 @@ This section covers the core concepts of the Android Lint API. The subsequent se >####Definition >An `IssueRegistry` is a registry which provides a list of checks to be performed on an Android project. -All checks* which should be considered during Lint analysis needs to be registered in an `IssueRegistry`. The built-in checks are registered within the `BuiltinIssueRegistry` class in the `com.android.tools.lint.checks` package. +All checks* which should be considered during Lint analysis need to be registered in an `IssueRegistry`. The built-in checks are registered within the `BuiltinIssueRegistry` class in the `com.android.tools.lint.checks` package. -In order to make custom Lint checks available for Lint analysis you need to subclass `IssueRegistry` an override its `getIssues` method which provides a `List` of `Issues`. Here is a straightforward example: +In order to make custom Lint checks available for Lint analysis you need to subclass `IssueRegistry` and override its `getIssues` method which provides a `List` of `Issues`. Here is a straightforward example: ```java public class CustomIssueRegistry extends IssueRegistry { @Override public List getIssues() { return Arrays.asList( //Note: - MyCustomCheck.ISSUE, //A check actually is a detector. + MyCustomCheck.ISSUE, //A check is actually a detector. MyAdvancedCheck.AN_ISSUE, //One detector can report MyAdvancedCheck.ANOTHER_ISSUE //multiple types of issues. ); @@ -24,7 +24,7 @@ public class CustomIssueRegistry extends IssueRegistry { } ``` -Last but not least it is necessary to reference your `IssueRegistry` class within your `MANIFEST`, such that it can be found by Lint. For Gradle-based projects this could be achieved by: +Last but not least, it is necessary to reference your `IssueRegistry` class within your `MANIFEST`, such that it can be found by Lint. For Gradle-based projects this could be achieved by: ```groovy jar { @@ -47,9 +47,9 @@ The `Detector` class is the central element for the definition of Lint rules. Mo In order to write a custom Lint rule you will need to subclass `Detector`. For certain use cases the Lint API also provides specific `Detectors` for your convenience, such as `LayoutDetector` or `ResourceXmlDetector` - but they are in turn also sub-classes of `Detector`. -Besides extending the `Detector` class you also need to implement a `Scanner` interface which defines how your `Detector` will scan the development artifacts! **By default the `Detector` class declares all methods of all available `Scanners` but you will notice that only the once of the implemented interface(s) will get called!** +Besides extending the `Detector` class you also need to implement a `Scanner` interface which defines how your `Detector` will scan the development artifacts! **By default the `Detector` class declares all methods of all available `Scanners` but you will notice that only the ones of the implemented interface(s) will get called!** -The different types of `Scanner` will be presented in the next section. +The different types of `Scanners` will be presented in the next section. ## 2.3 Scanner diff --git a/4_detectors/README.md b/4_detectors/README.md index 09e91ee..987a59b 100644 --- a/4_detectors/README.md +++ b/4_detectors/README.md @@ -7,11 +7,11 @@ Detectors represent the actual implementation of a custom Lint rule. Detectors h >####Definition > Simple detectors scan isolated artifacts of one type -(e.g. just code or just resources). Scan and evaluation is performed in one phase. +(e.g. just code or just resources). Scan and evaluation are performed in one phase. -In order to elaborate the aforementioned definition of simple detectors a bit let's have a look at Android's `HardcodedValuesDetecor` [1], which is a good example for a simple detector. It's responsible for detecting hardcoded values, which means if you have defined values in your layouts or menus directly instead of referencing them from a dedicated `strings.xml` file. +In order to elaborate the aforementioned definition of simple detectors a bit let's have a look at Android's `HardcodedValuesDetecor`, which is a good example of a simple detector. It's responsible for detecting hardcoded values, which means you have defined values in your layouts or menus directly instead of referencing them from a dedicated `strings.xml` file. -In order to detect such flaws only layout or menu files are scanned. In each file all value-containing attributes, such as `text` or `hint`, are visited. Their values are evaluated and in case they are no references, for instance they don't start with `@`, an `Issue` (see section 2.4) is reported. This evaluation is performed during scan phase directly: +In order to detect such flaws only layout or menu files are scanned. In each file all value-containing attributes, such as `text` or `hint`, are visited. Their values are evaluated and in case they are no references, for instance they don't start with `@`, an `Issue` (see section 2.4) is reported. This evaluation is performed during the scan phase directly: ```java public class HardcodedValuesDetector extends LayoutDetector { @@ -42,7 +42,7 @@ public class HardcodedValuesDetector extends LayoutDetector { Other examples for simple detector are `SdCardDetector` [2] or `MissingIdDetector` [3]. -In general, typically use cases for simple detectors are naming conventions or invalid value detection. +In general, typical use cases for simple detectors are naming conventions or invalid value detection. ## Advanced detectors From a401fc70d57a8a0cbffca928edcff1412eab6773 Mon Sep 17 00:00:00 2001 From: Fuad Balashov Date: Sun, 11 Feb 2018 10:35:22 -0500 Subject: [PATCH 2/4] Improving Links --- 4_detectors/README.md | 9 ++------- README.md | 12 ++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/4_detectors/README.md b/4_detectors/README.md index 987a59b..5c5434b 100644 --- a/4_detectors/README.md +++ b/4_detectors/README.md @@ -9,7 +9,7 @@ Detectors represent the actual implementation of a custom Lint rule. Detectors h > Simple detectors scan isolated artifacts of one type (e.g. just code or just resources). Scan and evaluation are performed in one phase. -In order to elaborate the aforementioned definition of simple detectors a bit let's have a look at Android's `HardcodedValuesDetecor`, which is a good example of a simple detector. It's responsible for detecting hardcoded values, which means you have defined values in your layouts or menus directly instead of referencing them from a dedicated `strings.xml` file. +In order to elaborate the aforementioned definition of simple detectors a bit let's have a look at Android's [`HardcodedValuesDetecor`](https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks), which is a good example of a simple detector. It's responsible for detecting hardcoded values, which means you have defined values in your layouts or menus directly instead of referencing them from a dedicated `strings.xml` file. In order to detect such flaws only layout or menu files are scanned. In each file all value-containing attributes, such as `text` or `hint`, are visited. Their values are evaluated and in case they are no references, for instance they don't start with `@`, an `Issue` (see section 2.4) is reported. This evaluation is performed during the scan phase directly: @@ -40,7 +40,7 @@ public class HardcodedValuesDetector extends LayoutDetector { } ``` -Other examples for simple detector are `SdCardDetector` [2] or `MissingIdDetector` [3]. +Other examples for simple detector are [`SdCardDetector`](https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java) or [`MissingIdDetector`](https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java). In general, typical use cases for simple detectors are naming conventions or invalid value detection. @@ -52,11 +52,6 @@ Scan and evaluation is performed in two phases. *This section is still under construction.* -##References -1. https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks -2. https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/SdCardDetector.java -3. https://android.googlesource.com/platform/tools/base/+/android-m-preview/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/MissingIdDetector.java - ## License ©2015 AndrĂ© Diermann diff --git a/README.md b/README.md index 404010c..d86702c 100644 --- a/README.md +++ b/README.md @@ -13,22 +13,22 @@ This reference guide aims to fill this gap and provide essential knowledge on ho ## Structure The guide is structured into six consecutive sections. -#### 1. Introduction +#### 1. [Introduction](1_introduction) This section introduces into the domain of Android Lint. It briefly describes the purpose, usage and configuration of this tool. -#### 2. Lint API basics +#### 2. [Lint API basics](2_lint_api_basics) This section covers the basics of the Android Lint API. It explains the core concepts of the API, such as `Issues`, `Detectors`, `Scanners` and `IssueRegistry`. -#### 3. Getting started +#### 3. [Getting started](3_getting_started) After the elaboration of the Lint API theory in [section 1](1_introduction/) and [section 2](2_lint_api_basics/) this chapter provides practical explanations and code to get you started writing your own custom Android Lint rules. -#### 4. Detectors +#### 4. [Detectors](4_detectors) This section demonstrates how to cope with `Detectors`. It showcases simple as well as advanced detecting techniques. -#### 5. Verification +#### 5. [Verification](5_verification) This section presents how to test and debug custom Lint rules. -#### 6. Application +#### 6. [Application](6_application) This section elaborates options to apply your custom Android Lint rules to your Android application project. ## Contributing From 27a1db5f763ae038706c008d91b0de80840365b6 Mon Sep 17 00:00:00 2001 From: Fuad Balashov Date: Sun, 11 Feb 2018 10:45:15 -0500 Subject: [PATCH 3/4] Adds links to additional resources --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d86702c..f573036 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,15 @@ This section presents how to test and debug custom Lint rules. #### 6. [Application](6_application) This section elaborates options to apply your custom Android Lint rules to your Android application project. + +## Additional Resources +If you are looking for more information on Lint the following resources can be helpful. + +1. [Android Docs on Lint](https://developer.android.com/studio/write/lint.html): Covers how to configure lint +2. [Android's Conceptual Overview of Lint](http://tools.android.com/tips/lint/writing-a-lint-check): Covers the concepts of writing android lint rules. +3. [A Presentation on Lint with Android](https://academy.realm.io/posts/360andev-matthew-compton-linty-fresh-java-android/): Presents is the same information as this guide, in video format. +4. [Writing Lint Rules with Annotations](https://android.jlelse.eu/writing-custom-lint-rules-and-integrating-them-with-android-studio-inspections-or-carefulnow-c54d72f00d30): Walks you through writing a lint rule that enforces an annotation. + ## Contributing Contribution to this guide is appreciated. Please refer to the [contribution guidelines](CONTRIBUTING.md) if you want to contribute something. From f0734833fc71429608386aaf44887833d2c71211 Mon Sep 17 00:00:00 2001 From: Fuad Balashov Date: Sun, 11 Feb 2018 10:46:36 -0500 Subject: [PATCH 4/4] Correcting 'Definiton' subtitle --- 2_lint_api_basics/README.md | 8 ++++---- 4_detectors/README.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/2_lint_api_basics/README.md b/2_lint_api_basics/README.md index dab5448..ec01ab9 100644 --- a/2_lint_api_basics/README.md +++ b/2_lint_api_basics/README.md @@ -4,7 +4,7 @@ This section covers the core concepts of the Android Lint API. The subsequent se ## 2.1 IssueRegistry ->####Definition +>#### Definition >An `IssueRegistry` is a registry which provides a list of checks to be performed on an Android project. All checks* which should be considered during Lint analysis need to be registered in an `IssueRegistry`. The built-in checks are registered within the `BuiltinIssueRegistry` class in the `com.android.tools.lint.checks` package. @@ -40,7 +40,7 @@ You will find a complete example with a lot more code in section 3. ## 2.2 Detector ->####Definition +>#### Definition >A detector is responsible for scanning through code and finding issue instances and reporting them. The `Detector` class is the central element for the definition of Lint rules. More precisely a `Detector` is an implementation of a Lint rule. It contains the logic to find certain problems in your development artifacts and map it to particular `Issues`. You will learn more about `Issues` in section 2.4. @@ -53,7 +53,7 @@ The different types of `Scanners` will be presented in the next section. ## 2.3 Scanner ->####Definition +>#### Definition >A scanner is a specialized interface for detectors. Currently seven different types of `Scanner` exist: @@ -81,7 +81,7 @@ As you can see, the `JavaScanner` interface provides dedicated methods for scann ## 2.4 Issue ->####Definition +>#### Definition >An issue is a type of problem you want to find and show to the user. An issue has an associated description, fuller explanation, category, priority, etc. So an `Issue` is the link between all previously described concepts. An `Issue` is registered within an `IssueRegistry`, such that Lint is aware of it, and it is detected and reported by a `Detector`, so that it becomes visible to the user. A `Detector` can report more than one type of `Issue`. diff --git a/4_detectors/README.md b/4_detectors/README.md index 5c5434b..e87d26d 100644 --- a/4_detectors/README.md +++ b/4_detectors/README.md @@ -5,7 +5,7 @@ Detectors represent the actual implementation of a custom Lint rule. Detectors h ## Simple detectors ->####Definition +>#### Definition > Simple detectors scan isolated artifacts of one type (e.g. just code or just resources). Scan and evaluation are performed in one phase. @@ -46,7 +46,7 @@ In general, typical use cases for simple detectors are naming conventions or inv ## Advanced detectors ->####Definition +>#### Definition > Advanced detectors scan related artifacts of different types. Scan and evaluation is performed in two phases.