-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds editorconfig + pre-commit (#403)
- Loading branch information
Showing
3 changed files
with
77 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,16 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.go] | ||
indent_style = tab | ||
|
||
[*.yaml] | ||
indent_style = space | ||
indent_size = 2 |
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,54 @@ | ||
#!/bin/bash | ||
|
||
# Check linting and unit tests before commiting | ||
# if linting failes the commit will be aborted and the linting will start auto fixing | ||
# if unit tests fail the commit will be aborted | ||
|
||
# Linting | ||
|
||
echo Shell: $SHELL | ||
|
||
## this will retrieve all of the .go files that have been | ||
## changed since the last commit | ||
STAGED_GO_FILES=$(git diff --cached --name-only -- '*.go') | ||
|
||
## we can check to see if this is empty | ||
if [[ $STAGED_GO_FILES == "" ]]; then | ||
echo "No Go Files to Update" | ||
exit 0 | ||
## otherwise we can do stuff with these changed go files | ||
else | ||
for file in $STAGED_GO_FILES; do | ||
gofmt -w $file | ||
goimports -w $file | ||
gci -w $file | ||
## add any potential changes from our formatting to the | ||
## commit | ||
git add $file | ||
done | ||
fi | ||
|
||
golangci-lint run --build-tags integration,containers_image_storage_stub | ||
res=$? | ||
if [[ $res -ne 0 ]]; then | ||
echo "Linting failed" | ||
exit 2 | ||
fi | ||
| ||
# Unit tests | ||
| ||
#exec < /dev/tty | ||
#read -p "Run unit tests[y/n]? " -n 1 -r | ||
#exec <&- | ||
REPLY=y | ||
| ||
if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
echo "Run unit tests..." | ||
go test ./... | ||
res=$? | ||
if [[ $res -ne 0 ]]; then | ||
echo "Unit test failed" | ||
exit 2 | ||
fi | ||
fi | ||
echo |
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