Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaster11 committed Sep 25, 2019
1 parent df52a77 commit 1e1d5df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
11 changes: 5 additions & 6 deletions .github/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/sh
set -e
DIR="$(dirname "$(command -v greadlink >/dev/null 2>&1 && greadlink -f "$0" || readlink -f "$0")")"

# Install tools to test our code-quality.
go get -u golang.org/x/lint/golint
go get -u golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go install "$DIR/shadow-fix.go"
go get -u honnef.co/go/tools/cmd/staticcheck

# Run the static-check tool
t=$(mktemp)
staticcheck -checks all ./... | grep -v " is overwritten before first use " >$t
staticcheck -checks all ./... | grep -v " is overwritten before first use " >$t || true
if [ -s $t ]; then
echo "Found errors via 'staticcheck'"
cat $t
Expand All @@ -16,17 +18,14 @@ if [ -s $t ]; then
fi
rm $t

# At this point failures cause aborts
set -e

# Run the linter
echo "Launching linter .."
golint ./...
echo "Completed linter .."

# Run the shadow-checker
echo "Launching shadowed-variable check .."
go vet -vettool=$(which shadow) ./...
go vet -vettool=$(which shadow-fix) ./...
echo "Completed shadowed-variable check .."

# Run golang tests
Expand Down
27 changes: 27 additions & 0 deletions .github/shadow-fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

// https://github.com/golang/go/issues/34053#issuecomment-532386030

import (
"flag"

"golang.org/x/tools/go/analysis/passes/shadow"
"golang.org/x/tools/go/analysis/unitchecker"
)

func main() {
unitchecker.Main(
shadow.Analyzer,
// ... other custom analyzers
)
}

func init() {
// go vet always adds this flag for certain packages in the standard library,
// which causes "flag provided but not defined" errors when running with
// custom vet tools.
// So we just declare it here and swallow the flag.
// See https://github.com/golang/go/issues/34053 for details.
// TODO: Remove this once above issue is resolved.
flag.String("unsafeptr", "", "")
}

0 comments on commit 1e1d5df

Please sign in to comment.