Skip to content

Commit

Permalink
[ci] add nonamedreturns linter (#703)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz authored Dec 19, 2024
1 parent f22ccb5 commit ad62038
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 218 deletions.
7 changes: 6 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters:
- depguard
- dogsled
- durationcheck
- exportloopref
- copyloopvar
- gci
- gochecknoinits
- gocritic
Expand All @@ -20,6 +20,7 @@ linters:
- ineffassign
- misspell
- nolintlint
- nonamedreturns
- prealloc
- revive
- sloglint
Expand Down Expand Up @@ -78,6 +79,10 @@ linters-settings:
deny:
- pkg: "gopkg.in/satori/go.uuid.v1"
desc: "Use https://github.com/gofrs/uuid instead. Satori/go.uuid is no longer maintained and has critical vulnerabilities."
nonamedreturns:
# Report named error if it is assigned inside defer.
# Default: false
report-error-in-defer: false
issues:
exclude-dirs:
- test/integration
Expand Down
25 changes: 11 additions & 14 deletions pkg/debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,28 @@ func NewServer(prefix, socketPath, httpAddr string, logger *log.Logger) *Server
}
}

func (s *Server) Init() (err error) {
func (s *Server) Init() error {
address := s.SocketPath

err = os.MkdirAll(path.Dir(address), 0o700)
if err != nil {
s.logger.Errorf("Debug HTTP server fail to create socket '%s': %v", address, err)
return err
if err := os.MkdirAll(path.Dir(address), 0o700); err != nil {
return fmt.Errorf("Debug HTTP server fail to create socket '%s': %w", address, err)
}

exists, err := utils.FileExists(address)
if err != nil {
s.logger.Errorf("Debug HTTP server fail to check socket '%s': %v", address, err)
return err
return fmt.Errorf("Debug HTTP server fail to check socket '%s': %w", address, err)
}

if exists {
err = os.Remove(address)
if err != nil {
s.logger.Errorf("Debug HTTP server fail to remove existing socket '%s': %v", address, err)
return err
if err := os.Remove(address); err != nil {
return fmt.Errorf("Debug HTTP server fail to check socket '%s': %w", address, err)
}
}

// Check if socket is available
listener, err := net.Listen("unix", address)
if err != nil {
s.logger.Errorf("Debug HTTP server fail to listen on '%s': %v", address, err)
return err
return fmt.Errorf("Debug HTTP server fail to listen on '%s': %w", address, err)
}

s.logger.Infof("Debug endpoint listen on %s", address)
Expand Down Expand Up @@ -153,7 +148,9 @@ func handleFormattedOutput(writer http.ResponseWriter, request *http.Request, ha
}
}

func transformUsingFormat(w io.Writer, val interface{}, format string) (err error) {
func transformUsingFormat(w io.Writer, val interface{}, format string) error {
var err error

switch format {
case "yaml":
enc := yaml.NewEncoder(w)
Expand Down
10 changes: 6 additions & 4 deletions pkg/filter/jq/jq_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// jqExec is a subprocess implementation of the jq filtering.
func jqExec(jqFilter string, jsonData []byte, libPath string) (result string, err error) {
func jqExec(jqFilter string, jsonData []byte, libPath string) (string, error) {
var cmd *exec.Cmd
if libPath == "" {
cmd = exec.Command("jq", jqFilter)
Expand All @@ -19,14 +19,16 @@ func jqExec(jqFilter string, jsonData []byte, libPath string) (result string, er
}

var stdinBuf bytes.Buffer
_, err = stdinBuf.WriteString(string(jsonData))
_, err := stdinBuf.WriteString(string(jsonData))
if err != nil {
panic(err)
}
cmd.Stdin = &stdinBuf

var stdoutBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
var stderrBuf bytes.Buffer

cmd.Stdin = &stdinBuf
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf

err = executor.Run(cmd)
Expand Down
19 changes: 10 additions & 9 deletions pkg/hook/config/config_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,31 @@ type KubeNamespaceSelectorV0 struct {
}

// ConvertAndCheckV0 fills non-versioned structures and run inter-field checks not covered by OpenAPI schemas.
func (cv0 *HookConfigV0) ConvertAndCheck(c *HookConfig) (err error) {
c.OnStartup, err = c.ConvertOnStartup(cv0.OnStartup)
if err != nil {
func (cv0 *HookConfigV0) ConvertAndCheck(c *HookConfig) error {
var err error

if c.OnStartup, err = c.ConvertOnStartup(cv0.OnStartup); err != nil {
return err
}

c.Schedules = []htypes.ScheduleConfig{}
for i, rawSchedule := range cv0.Schedule {
err := cv0.CheckSchedule(rawSchedule)
if err != nil {
return fmt.Errorf("invalid schedule config [%d]: %v", i, err)
if err := cv0.CheckSchedule(rawSchedule); err != nil {
return fmt.Errorf("invalid schedule config [%d]: %w", i, err)
}

schedule, err := cv0.ConvertSchedule(rawSchedule)
if err != nil {
return err
}

c.Schedules = append(c.Schedules, schedule)
}

c.OnKubernetesEvents = []htypes.OnKubernetesEventConfig{}
for i, kubeCfg := range cv0.OnKubernetesEvent {
err := cv0.CheckOnKubernetesEvent(kubeCfg, fmt.Sprintf("onKubernetesEvent[%d]", i))
if err != nil {
return fmt.Errorf("invalid onKubernetesEvent config [%d]: %v", i, err)
if err := cv0.CheckOnKubernetesEvent(kubeCfg, fmt.Sprintf("onKubernetesEvent[%d]", i)); err != nil {
return fmt.Errorf("invalid onKubernetesEvent config [%d]: %w", i, err)
}

monitor := &kubeeventsmanager.MonitorConfig{}
Expand Down
Loading

0 comments on commit ad62038

Please sign in to comment.