Saturday, March 29, 2014

Inspection (lint and Intellij rules)

A developer should always check his code for Lint warnings/errors and intellij rules, and seek to minimize the amount of warnings/errors. As a team we will use a unified set of Lint rules, that will help us set the base rules for Lint checker.

A check will be performed on the current module only, and not on 3rd party component (Meaning the App module shouldn’t inspect/check the SDK library for example).


Shared Config File

The secret to have a team work working with the same set of rules relies in the “xyz_inspection_config.xml” file. This file should be maintained in each of the Android modules with the respective name.
A separate config will be set to each module separately.


Steps to setup your Inspector:

  1. Start “Inspect code” dialog from your Android Studio.
  2. Due to a bug, you should select a “custom scope” that will point to the “Src” folder in your module, for example:
  3. Now, to have the same rules as your team members, select “Inspection profile” and “Import” the set of rules that you have in your git. Make sure you do that occasionally as your team members might update the rules. (You can do that as well :))
  4. Hit “OK” and happy hunting!


What to do with the results?

  • Errors - Do not commit your code
  • Warning - Do not commit your code OR suppress and add a TODO-{Name}
  • Weak warning and Typo - It’s OK. Should be fixed on the next “weak warnings and Typo fest :)”


Suppress error vs. change the rules?

Suppressing an error is the developer declaration “this is violating the rules BUT It’s ok because of XYZ”. When suppressing - make sure you add a comment to explain it if needed.

Changing the rules (the config file) is when we decide “This violation type doesn’t concern us in the project”, when doing that we should think of the “greater good” of the project, and not only on the scope of the current work that we do. If you’ve done that - don’t forget to commit the file to git.