Anki-Android
Anki-Android copied to clipboard
Make possible to commit hunks on Kotlin again
Fixes
Fixes #9390
Approach
Replaced the old runKtlint() code with the one generated by ./gradlew addKtlintFormatGitPreCommitHook
for reference, see https://github.com/JLLeitschuh/ktlint-gradle#additional-helper-tasks, and for the implementation, https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt
The idea came from https://github.com/ankidroid/Anki-Android/issues/9390#issuecomment-950353851
How Has This Been Tested?
https://user-images.githubusercontent.com/69634269/183875558-937f7fc7-a4a6-4178-ad20-cb597f11de31.mp4
Checklist
Please, go through these checks before submitting the PR.
- [X] You have not changed whitespace unnecessarily (it makes diffs hard to read)
- [X] You have a descriptive commit message with a short title (first line, max 50 chars).
- [X] Your code follows the style of the project (e.g. never omit braces in
if
statements) - [X] You have commented your code, particularly in hard-to-understand areas
- [X] You have performed a self-review of your own code
- [ ] UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
- [ ] UI Changes: You have tested your change using the Google Accessibility Scanner
From https://github.com/ankidroid/Anki-Android/issues/9390#issuecomment-950353851
Perhaps if we used one of the plugins (this is most popular: https://github.com/jlleitschuh/ktlint-gradle#additional-helper-tasks) and just integrated it's pre-commit hook (and IDEA style file generation) we'd get editor support for style in Android Studio, and we'd get formatting as a pre-commit hook, and everyone else already using that plugin will have solved all the problems we're cutting our teeth on?
I'd like to see a Proof of concept that killed our pre-commit hook and tried integrating that plugin with it's IDEA style + commit hook)
This PR is only for fixing the pre-commit problem. As I found very reasonable to try using the plugin IDEA style as well and the repo's kotlin code style barely exists, I'll peel it to a separate issue.
@david-allison I cleaned and then rebuilt the project before testing it.
AFAIK, git hooks only works if they are on the ".git/hooks" directory, and AnkiDroid uses gradle to make a copy of "./pre-commit" on it. So yeah, just rebuild the app