Skip to content

Commit

Permalink
Improve go linting scripts (improbable-eng#340)
Browse files Browse the repository at this point in the history
* Fix gofmt issue

* Improve linting script

* Tighten up what gets printed.

* Print output generated by `generate-docs.sh` on failure.

* Fix invocation of lint script by Travis
  • Loading branch information
jonny-improbable authored Feb 11, 2019
1 parent 801c499 commit 1922a55
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 72 deletions.
22 changes: 0 additions & 22 deletions go/checkup.sh

This file was deleted.

44 changes: 0 additions & 44 deletions go/fixup.sh

This file was deleted.

12 changes: 12 additions & 0 deletions go/generate-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo "Generating markdown using godocdown in..."
oldpwd="$(pwd)"
for i in $(find . -iname 'doc.go'); do
dir="${i%/*}"
echo "- $dir"
cd "${dir}"
"${GOPATH}/bin/godocdown" -heading=Title -o DOC.md
ln -s DOC.md README.md 2> /dev/null # can fail
cd "${oldpwd}"
done;
2 changes: 1 addition & 1 deletion go/grpcwebproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
flagBindAddr = pflag.String("server_bind_address", "0.0.0.0", "address to bind the server to")
flagHttpPort = pflag.Int("server_http_debug_port", 8080, "TCP port to listen on for HTTP1.1 debug calls.")
flagHttpTlsPort = pflag.Int("server_http_tls_port", 8443, "TCP port to listen on for HTTPS (gRPC, gRPC-Web).")

runHttpServer = pflag.Bool("run_http_server", true, "whether to run HTTP server")
runTlsServer = pflag.Bool("run_tls_server", true, "whether to run TLS server")

Expand Down
62 changes: 62 additions & 0 deletions go/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Script that checks the code for errors.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"

function print_real_go_files {
grep --files-without-match 'DO NOT EDIT!' $(find . -iname '*.go')
}

function check_no_documentation_changes {
echo "- Running generate-docs.sh"
output=$(./generate-docs.sh)
if [[ $? -ne 0 ]]; then
echo $output
echo "ERROR: Failed to generate documentation."
exit 1
fi

git diff --name-only | grep -q DOC.md
if [[ $? -ne 1 ]]; then
echo "ERROR: Documentation changes detected, please commit them."
exit 1
fi
}

function check_gofmt {
echo "- Running gofmt"
out=$(gofmt -l -w $(print_real_go_files))
if [[ ! -z $out ]]; then
echo "ERROR: gofmt changes detected, please commit them."
exit 1
fi
}

function goimports_all {
echo "- Running goimports"
${GOPATH}/bin/goimports -l -w $(print_real_go_files)
if [[ $? -ne 0 ]]; then
echo "ERROR: goimports changes detected, please commit them."
exit 1
fi
}

function govet_all {
echo "- Running govet"
ret=0
for i in $(print_real_go_files); do
output=$(go tool vet -all=true -tests=false ${i})
ret=$(($ret | $?))
echo -n ${output}
done;
if [[ $ret -ne 0 ]]; then
echo "ERROR: govet errors detected, please commit/fix them."
exit 1
fi
}

check_no_documentation_changes
check_gofmt
goimports_all
govet_all
echo
7 changes: 2 additions & 5 deletions lint-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
set -e

echo "Linting go sources"
pushd ./go
./checkup.sh
./fixup.sh
popd
cd go && ./lint.sh && cd ..

echo "Linting Typescript sources"
echo "Linting TypeScript sources"
npm run lint

0 comments on commit 1922a55

Please sign in to comment.