Provides hooks to format Kotlin code using ktlint
and Swift code using SwiftFormat
ktlint
and SwiftFormat
should be added via Gradle and SPM so you can control their version in your codebase, avoiding someone having a different version on their machine.
- Install pre-commit on your machine
- Add ktlint-gradle to your project
- Add SwiftFormat to your project
- Add the following in your
.pre-commit-config.yaml
:
repos:
- repo: https://github.com/ema987/pre-commit-kmm
rev: master
hooks:
- id: ktlint-format
fail_fast: true
- id: swift-format
fail_fast: true
Notes:
- change
rev
to another tag or specific commit if needed - SwiftFormat can also run on Linux machines if you install Swift first. See Install Swift on Linux for GitHub actions.
- if you want all the hooks to run even if there is an error in a previos one, remove the
fail_fast
param, it defaults tofalse