go/utils/repofmt/check_fmt.sh: Add a script to format the repo appropriately.

This commit is contained in:
Aaron Son
2019-08-07 12:20:25 -07:00
parent 6a35448c5a
commit 83b776af46
2 changed files with 25 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ if [ "$bad_files" != "" ]; then
echo "ERROR: The following files do not match goimports output:"
echo "$bad_files"
echo
echo "Please format the go code in the repository with 'goimports -l -local github.com/liquidata-inc/dolt .'"
echo "Please format the go code in the repository with './utils/repofmt/format_repo.sh'"
exit 1
fi
@@ -23,5 +23,7 @@ done)
if [ "$bad_files" != "" ]; then
echo "ERROR: The following files have more than three import groups:"
echo "$bad_files"
echo
echo "Please format the go code in the repository with './utils/repofmt/format_repo.sh'"
exit 1
fi

22
go/utils/repofmt/format_repo.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -eo pipefail
script_dir=$(dirname "$0")
cd $script_dir/../..
goimports -w -local github.com/liquidata-inc/dolt .
bad_files=$(find . -name '*.go' | while read f; do
if [[ $(awk '/import \(/{flag=1;next}/\)/{flag=0}flag' < $f | egrep -c '$^') -gt 2 ]]; then
echo $f
fi
done)
if [ "$bad_files" != "" ]; then
for f in $bad_files; do
awk '/import \(/{flag=1}/\)/{flag=0}flag&&!/^$/||!flag' < "$f" > "$f.bak"
mv "$f.bak" "$f"
done
goimports -w -local github.com/liquidata-inc/dolt .
fi