-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from navikt/ktlint-husky
Eget node prosjekt for å kjøre ktlint med husky
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
changedKotlinFiles=$(git diff --name-only --cached | grep '\.kt[s"]\?$' || true) | ||
|
||
if [ -n "${changedKotlinFiles-unset}" ]; then | ||
kotlinversion=$(ktlint -v) | ||
expectedVersion="ktlint version 1.3.1" | ||
if [ "$kotlinversion" != "$expectedVersion" ]; then | ||
echo "Running version $kotlinversion needs to be $expectedVersion" | ||
exit 1 | ||
fi | ||
|
||
echo "🛠 Running ktlint" | ||
|
||
#store the result of the commit in a variable and split into array items with newline | ||
committedFiles=$(git diff --name-only --cached --diff-filter=d) | ||
files=$(echo $committedFiles | tr ";" "\\n") | ||
|
||
# https://github.com/pinterest/ktlint pre-commit hook | ||
git diff --name-only --cached | grep '\.kt[s"]\?$' | xargs ktlint -F | ||
echo "✍️ Formatted kotlin files" | ||
|
||
#replay items in the commits array and add only those files | ||
for file in $files | ||
do | ||
git add $file | ||
done | ||
fi | ||
|
||
echo "🏆 Files staged" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "ktlint", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"prepare": "cd ../ && husky .husky" | ||
}, | ||
"devDependencies": { | ||
"husky": "~9.0.11" | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
husky@~9.0.11: | ||
version "9.0.11" | ||
resolved "https://registry.yarnpkg.com/husky/-/husky-9.0.11.tgz#fc91df4c756050de41b3e478b2158b87c1e79af9" | ||
integrity sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw== |