Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Improve your code with Lint checks for Kotlin

Improve your code with Lint checks for Kotlin

The linter tool has been around for a long time, and sometimes we forget it exists or we just use it as it comes out of the box.
But there is so much more we can do to leverage this tool, and tailor it to our needs.
From finding vulnerabilities in our code, all the way to promoting company wide guidelines.

Emma Tresanszki

October 24, 2019
Tweet

More Decks by Emma Tresanszki

Other Decks in Programming

Transcript

  1. Android Lint Philosophy #1 “False positives are better than false

    negatives.” #2 Focus on Android issues - Leave general coding issues to the IDE
  2. How to use it ? IDE Gradle - On the

    fly - Run inspections by name - Command line - xml/html reports
  3. Goal • Run lint on every build • If there

    are any new lint issues, break the build • Get to zero unchecked lint errors and warnings
  4. @suppressing stuff around • Sometimes you just don’t care •

    @Unused in library • You don’t want to break the build
  5. @suppressing stuff around • Sometimes you just don’t care •

    @Unused in library • You don’t want to break the build
  6. Supported lint checks Starting with the Android Gradle Plugin 3.1.0

    you can apply Android Lint to Java / Kotlin modules.
  7. UAST Universal Abstract Syntax Tree - UElement -> root of

    everything - UFile -> Compilation unit - UClass -> A class declaration - UMember - UField - UMethod - ...
  8. UastScanner Convenience callbacks to check - Any calls to a

    method of a given name - Any instantiations of a given class - Any subclasses or sub interfaces - Any Android resource reference - Annotation usages - Any AST nodes by type - ...
  9. This presentation will soon be available on the droidcon London

    website at the following link https:/ /skillsmatter.com/conferences/11785-droidcon-lo ndon-2019#skillscasts @EmmaTresanszki https:/ /github.com/emmaChristine/DCLondon
  10. References 1. https:/ /developer.android.com/studio/write/lint 2. https:/ /en.wikipedia.org/wiki/Lint_(software) 3. https:/ /github.com/pinterest/ktlint/tree/master/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/st

    andard 4. https:/ /medium.com/@vanniktech/running-lint-on-java-kotlin-modules-55b747d0e5f3 5. https:/ /www.bignerdranch.com/blog/building-custom-lint-checks-in-android/ 6. https://www.youtube.com/watch?v=p8yX5-lPS6o&feature=youtu.be&t=1353 7. https://www.youtube.com/watch?v=ffH-LD5uP4s 8. https://developer.android.com/studio/write/lint#manuallyRunInspections 9. https://medium.com/@intelia/getting-the-most-out-of-android-lint-6df05a7ab054 10. https://tech.yplanapp.com/2016/08/10/android-lint/ 11. https://www.youtube.com/watch?v=ffH-LD5uP4s 12. Photo by Kelly Sikkema on Unsplash Photo by Joanna Kosinska on Unsplash