mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
go/utils/repofmt/check_fmt.sh: Add a script to format the repo appropriately.
This commit is contained in:
@@ -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
22
go/utils/repofmt/format_repo.sh
Executable 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
|
||||
Reference in New Issue
Block a user