forked from improbable-eng/grpc-web
-
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.
Improve go linting scripts (improbable-eng#340)
* 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
1 parent
801c499
commit 1922a55
Showing
6 changed files
with
77 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
#!/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; |
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
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,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 |
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