Skip to content

Commit 0d94acc

Browse files
committed
First commit
0 parents  commit 0d94acc

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- id: ktlint-format
2+
name: Format Kotlin using ktlint
3+
entry: runKtLintFormat
4+
language: script
5+
files: \.kt$
6+
- id: swift-format
7+
name: Format Swift using SwiftFormat
8+
entry: runSwiftFormat
9+
language: script
10+
files: \.swift$

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Emanuele Papa
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# pre-commit hooks for KMM projects
2+
Provides hooks to format Kotlin code using [`ktlint`](https://github.com/pinterest/ktlint) and Swift code using [`SwiftFormat`](https://github.com/nicklockwood/SwiftFormat)
3+
4+
## Installation
5+
`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.
6+
7+
1. Install [pre-commit](https://pre-commit.com) on your machine
8+
2. Add [ktlint-gradle](https://github.com/JLLeitschuh/ktlint-gradle) to your project
9+
3. Add [SwiftFormat](https://github.com/nicklockwood/SwiftFormat#1-create-a-buildtools-folder-and-packageswift) to your project
10+
4. Add the following in your `.pre-commit-config.yaml`:
11+
```yaml
12+
repos:
13+
- repo: https://github.com/ema987/pre-commit-kmm
14+
rev: master
15+
hooks:
16+
- id: ktlint-format
17+
fail_fast: true
18+
- id: swift-format
19+
fail_fast: true
20+
```
21+
22+
Notes:
23+
- change `rev` to another tag or specific commit if needed
24+
- if you want all the hooks to run even if there is an error in a previos one, remove the `fail_fast` param, it defauls to `false`

runKtLintFormat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
./gradlew ktlintFormat

runSwiftFormat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cd iosApp/BuildTools
3+
swift run -c release swiftformat ../iosApp

0 commit comments

Comments
 (0)