Skip to content

Commit 98b8435

Browse files
authored
update to latest ktlint version and add various improvements #1
2 parents c0b8743 + 9a6f8b7 commit 98b8435

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- id: ktlint
2-
name: Ktlint formatter for your kotlin code
2+
name: ktlint
33
description: Runs ktlint over your kotlin files
44
entry: ./run-ktlint.sh
55
language: script

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ Usage:
66
```
77
repos:
88
- repo: https://github.com/maltzj/ktlint-pre-commit
9-
sha: e5bee17
9+
rev: master
1010
hooks:
1111
- id: ktlint
1212
```
1313

14+
If you want to make use of the formatting functionality of ktlint you can configure
15+
the hook as follows:
16+
repos:
17+
- repo: https://github.com/maltzj/ktlint-pre-commit
18+
rev: master
19+
hooks:
20+
- id: ktlint
21+
args: [-F]
22+
```
23+
24+
1425
*Notes*:
1526
* This file stores ktlint in a `.cache/` directory so that it doesn't need to be re-downloaded each time. You will probably want to add `.cache/` to the `.gitignore` file of the project which uses this hook.
1627
* The first time this hook runs it will need to download ktlint, which takes a

run-ktlint.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#!/usr/bin/env sh
2-
mkdir -p .cache
3-
cd .cache
4-
if [ ! -f ktlint ]
2+
3+
REPOSITORY="https://github.com/pinterest/ktlint"
4+
VERSION=0.41.0
5+
CACHE=".cache"
6+
KTLINT="${CACHE}/ktlint-${VERSION}"
7+
8+
mkdir -p "${CACHE}"
9+
if [ ! -f "${KTLINT}" ]
510
then
6-
curl -sSLO https://github.com/shyiko/ktlint/releases/download/0.29.0/ktlint
7-
chmod 755 ktlint
11+
echo "Installing ${KTLINT}"
12+
curl -#SLf "${REPOSITORY}/releases/download/$VERSION/ktlint" > "${KTLINT}"
13+
chmod 755 "${KTLINT}"
814
fi
9-
cd ..
1015

11-
changed_kotlin_files=$(git diff --cached --name-only --diff-filter=ACMR | grep ".*kt$" )
12-
echo $changed_kotlin_files
13-
.cache/ktlint $changed_kotlin_files
16+
${KTLINT} $*

0 commit comments

Comments
 (0)