I'm trying to create pre-commit hook with code style check and other errors. It's a multi-module project in Android Studio (java and kotlin). I was hoping to use lint, but no luck.
My condition is to check only new and modified files (baseline is in order ofc) as the project is way too big to run checks on every commit on every file.
My sh command looks like this:
git diff --name-only HEAD | xargs -I '{}' ./gradlew lint {}\;
It translates to:
./gradlew lint /path/to/the/file.java
But it always fails on trying to find task called "the path to the file".
When I try to use lint from Android SDK it just prints main: Error: "main" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead.
Any advice?
android.lintOptions
). Also I don't think that running lint over specific files is a good idea: often we declare XML resources and later use them from Java/Kotlin code - this way you lose some important lint features (like unused resources), which require to analyze multiple scopes and files. – Bratton