Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable more golanglint linters #2439

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
- exhaustive
- exportloopref
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
- gosec
- gosimple
Expand All @@ -26,11 +27,13 @@ linters:
- nolintlint
- nonamedreturns
- nosprintfhostport
- perfsprint
- reassign
- revive
- staticcheck
- stylecheck
- tenv
- testifylint
- thelper
- testableexamples
- typecheck
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ ifeq (${LINT_EXISTS}, )
@exit 1
endif
golangci-lint run
@cd integration && golangci-lint run

govulncheck: ## run govulncheck on the source files
ifeq (${GOVULNCHECK_EXISTS}, )
Expand Down
2 changes: 1 addition & 1 deletion cmd/exporters/prometheus/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (p *Prometheus) startHTTPD(addr string, port int) {
mux.HandleFunc("/metrics", p.ServeMetrics)

server := &http.Server{
Addr: addr + ":" + fmt.Sprint(port),
Addr: addr + ":" + strconv.Itoa(port),
Handler: mux,
ReadHeaderTimeout: 60 * time.Second,
}
Expand Down
4 changes: 2 additions & 2 deletions integration/certer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func addCertificateAuthToHarvestUser() error {
if err != nil {
var oe models.OntapError
if errors.As(err, &oe) {
if oe.StatusCode == 409 {
if oe.StatusCode == http.StatusConflict {
// duplicate entry - that's fine, ignore
continue
}
Expand Down Expand Up @@ -355,7 +355,7 @@ func deleteCertificates(certificates models.Certificates) error {
Pathf("/api/security/certificates/%s", record.UUID).
ToString(&resp).
AddValidator(func(response *http.Response) error {
if response.StatusCode != 200 {
if response.StatusCode != http.StatusOK {
return fmt.Errorf("failed to delete ertificates. statusCode=%d status=%s", response.StatusCode, response.Status)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions integration/test/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetPerfFileWithQosCounters(source string, target string) string {
writeBuffer := bufio.NewWriter(writeFile)
file, err := os.Open(utils.GetHarvestRootDir() + "/" + source)
if err != nil {
log.Error().Err(err)
log.Error().Err(err).Send()
}
defer func(file *os.File) { _ = file.Close() }(file)

Expand All @@ -40,7 +40,7 @@ func GetPerfFileWithQosCounters(source string, target string) string {
_, _ = writeBuffer.WriteString(lineString + "\n")
}
if err := scanner.Err(); err != nil {
log.Error().Err(err)
log.Error().Err(err).Send()
}
_ = writeBuffer.Flush()
return modifiedFilePath
Expand Down
2 changes: 1 addition & 1 deletion integration/test/utils/http_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func GetResponseBody(url string) ([]byte, error) {
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
return nil, err
}
resp.Body.Close()
return body, nil
}

Expand Down
10 changes: 7 additions & 3 deletions integration/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -203,9 +204,12 @@ func CreateGrafanaToken() string {
log.Info().Msg("Creating grafana API Key.")
url := GetGrafanaHTTPURL() + "/api/auth/keys"
method := "POST"
name := fmt.Sprint(time.Now().Unix())
name := strconv.FormatInt(time.Now().Unix(), 10)
values := map[string]string{"name": name, "role": "Admin"}
jsonValue, _ := json.Marshal(values)
jsonValue, err := json.Marshal(values)
if err != nil {
panic(err)
}
data := SendReqAndGetRes(url, method, jsonValue)
key := fmt.Sprintf("%v", data["key"])
if len(key) > 0 {
Expand Down Expand Up @@ -310,7 +314,7 @@ func RemoveDuplicateStr(strSlice []string) []string {

func SetupLogging() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
zerolog.ErrorStackMarshaler = MarshalStack
zerolog.ErrorStackMarshaler = MarshalStack //nolint:reassign
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: true}).
With().Caller().Stack().Timestamp().Logger()
}
Expand Down
Loading