-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code style cleanup and adding golangci-lint
- Loading branch information
Aaron Hurt
committed
Mar 27, 2024
1 parent
6d75bde
commit ad789c5
Showing
16 changed files
with
147 additions
and
157 deletions.
There are no files selected for viewing
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,25 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v4 | ||
with: | ||
version: v1.57 |
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,22 @@ | ||
# Refer to golangci-lint's example config file for more options and information: | ||
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml | ||
|
||
run: | ||
timeout: 5m | ||
modules-download-mode: readonly | ||
|
||
linters: | ||
enable: | ||
- errcheck | ||
- gofmt | ||
- goimports | ||
- gocyclo | ||
- govet | ||
- misspell | ||
- revive | ||
- staticcheck | ||
|
||
issues: | ||
exclude-use-default: false | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 |
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ build: | |
@build/build.sh | ||
|
||
test: | ||
@go test -v | ||
@go test -v ./... | ||
|
||
release: | ||
@build/build.sh -r | ||
|
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 |
---|---|---|
@@ -1,79 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
## ensure we have staticcheck | ||
## https://github.com/golang/lint | ||
if ! staticcheck=$(type -p "${GOPATH}/bin/staticcheck"); then | ||
echo -n "Installing staticcheck ... " | ||
go install honnef.co/go/tools/cmd/staticcheck@latest | ||
echo "done" | ||
staticcheck=$(type -p "${GOPATH}/bin/staticcheck") | ||
fi | ||
|
||
## ensure we have the misspell tool | ||
## https://github.com/client9/misspell | ||
if ! misspell=$(type -p "${GOPATH}/bin/misspell"); then | ||
echo -n "Installing misspell ... " | ||
go install github.com/client9/misspell/cmd/misspell@latest | ||
echo "done" | ||
misspell=$(type -p "${GOPATH}/bin/misspell") | ||
fi | ||
|
||
## ensure we have the gocyclo tool | ||
## https://github.com/fzipp/gocyclo | ||
if ! gocyclo=$(type -p "${GOPATH}/bin/gocyclo"); then | ||
echo -n "Installing gocyclo ... " | ||
go install go install github.com/fzipp/gocyclo/cmd/gocyclo@latest | ||
echo "done" | ||
gocyclo=$(type -p "${GOPATH}/bin/gocyclo") | ||
fi | ||
|
||
## check formatting ignoring git and vendor | ||
fmtTest=$(find . -name '*.go' -not -path './.git/*' -not -path './vendor/*' | xargs gofmt -l -s 2>&1) | ||
if [ ! -z "$fmtTest" ]; then | ||
echo "gofmt failed" | ||
echo "$fmtTest" | ||
exit 1 | ||
else | ||
echo "gofmt succeeded" | ||
fi | ||
|
||
## run go vet ignoring vendor and the silly "Error" bug/feature | ||
## https://github.com/golang/go/issues/6407 | ||
vetTest=$(go vet ./... 2>&1 | egrep -v '^vendor/|\s+vendor/|/vendor/|^exit\ status|\ possible\ formatting\ directive\ in\ Error\ call') | ||
if [ ! -z "$vetTest" ]; then | ||
echo "go vet failed" | ||
echo "$vetTest" | ||
exit 1 | ||
else | ||
echo "go vet succeeded" | ||
fi | ||
|
||
## run staticcheck ignoring vendor | ||
staticTest=$(${staticcheck} ./... 2>&1 | egrep -v '^vendor/|\s+vendor/|/vendor/') | ||
if [ ! -z "$statitTest" ]; then | ||
echo "staticcheck failed" | ||
echo "$staticTest" | ||
exit 1 | ||
else | ||
echo "staticcheck succeeded" | ||
fi | ||
|
||
## check misspell ignoring git, vendor and 3rdparty | ||
spellTest=$(find . -name '*' -not -path './.git/*' -not -path './vendor/*' -not -path './3rdparty/*' | xargs ${misspell} 2>&1 | echo) | ||
if [ ! -z "$spellTest" ]; then | ||
echo "misspell failed" | ||
echo "$spellTest" | ||
exit 1 | ||
else | ||
echo "misspell succeeded" | ||
fi | ||
|
||
## check gocyclo ignoring git and vendor | ||
cycloTest=$(find . -name '*.go' -not -path './.git/*' -not -path './vendor/*' | xargs ${gocyclo} -over 15 2>&1 | echo) | ||
if [ ! -z "$cycloTest" ]; then | ||
echo "gocyclo failed" | ||
echo "$cycloTest" | ||
exit 1 | ||
else | ||
echo "gocyclo succeeded" | ||
fi | ||
## ensure golangci-lint - https://golangci-lint.run | ||
golangci="$(go env GOPATH)/bin/golangci-lint" | ||
if ! ${golangci} version &> /dev/null; then | ||
echo "Installing golangci-lint binary to ${golangci}" | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ | ||
sh -s -- -b "$(go env GOPATH)/bin" v1.57.1 | ||
echo "done" | ||
fi | ||
|
||
## run golangci-lint - all config in .golangci.yml | ||
lintRun=$(${golangci} run --show-stats ./...) | ||
lintRet=$? | ||
echo "golangci-lint ${lintRun}" | ||
exit $lintRet |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package check provides the check cli command | ||
package check | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package update provides the update cli command | ||
package update | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package common contains code shared between packages | ||
package common | ||
|
||
import ( | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Package dns defines the DNS service backend interface | ||
package dns | ||
|
||
// RType represents a dns record type | ||
|
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
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
Oops, something went wrong.