Lin
Lin is an Android Lint tool made simpler. It has two different goals:
- To create a set of highly opinionated detectors to apply to your Android projects.
- To offer a Kotlin DSL to write your own detectors in a much easier way.
How to use
Add the JitPack repository to your build file:
Lin - Detectors
Add the detectors
module dependencies to your project and the dsl
module as part of the lint classpath:
Lin - DSL (Domain Specific Language)
If you want to write your own detectors just add the dsl
and annotations
modules to your linting project:
How to write your own detectors
Lin offers a DSL (Domain Specific Language) to write your own detectors easily. The API is focused on representing your rules as concisely as possible. Let's bisect an example of a detector to understand how it works:
Quantifiers
You can specify your rules using quantifiers, that is, numeric restrictions to how many times you are expecting a specific rule to appear in order to be reported.
The list of available quantifiers is:
Storage
Lin detectors can store and retrieve information from a provided map. This is really useful if you have dependant rules where one of them might depend on the value of another, e.g. an activity class name having the same name as the layout it renders.
Because Lin uses backtracking on the process of finding the best match for rules it's highly discouraged to store information by yourself, intead you should use the storage
property provided in the suchThat
block.
The storage
property is just a MutableMap<String, String>
. The matching algorithm takes care of keeping the map in a coherent state while doing the search so that you won't find values stored in failing rules. All siblings and child nodes will see stored values.
It's also important to keep in mind that Lin will try to match rules in any order. The most important implication is that even if you define a rule in a specific order Lin might find matches in the opposite:
Even if the expression storing things in the storage is defined before, that order is not honored when looking for the best match of rules, so it might happen that storage["node"]
is null.
Badge
Show the world you're using Lin.