diff --git a/.golangci.yml b/.golangci.yml index 6c5366aecb..0c6243602d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ linters: - gosimple - govet - grouper + - ifshort - importas - ineffassign - makezero diff --git a/pkg/background/request_process.go b/pkg/background/request_process.go index a5610bd2b3..c1dab7f115 100644 --- a/pkg/background/request_process.go +++ b/pkg/background/request_process.go @@ -53,11 +53,9 @@ func (c *Controller) MarkUR(ur *kyvernov1beta1.UpdateRequest) (*kyvernov1beta1.U } func (c *Controller) UnmarkUR(ur *kyvernov1beta1.UpdateRequest) error { - _, err := c.PatchHandler(ur, "") - if err != nil { + if _, err := c.PatchHandler(ur, ""); err != nil { return err } - if ur.Spec.Type == kyvernov1beta1.Mutate && ur.Status.State == kyvernov1beta1.Completed { return c.kyvernoClient.KyvernoV1beta1().UpdateRequests(config.KyvernoNamespace()).Delete(context.TODO(), ur.GetName(), metav1.DeleteOptions{}) } diff --git a/pkg/cosign/init.go b/pkg/cosign/init.go index be557b35f2..5163c0b4ba 100644 --- a/pkg/cosign/init.go +++ b/pkg/cosign/init.go @@ -7,10 +7,8 @@ import ( ) func Init() error { - certs := fulcio.GetRoots() - if certs == nil { + if fulcio.GetRoots() == nil { return fmt.Errorf("failed to initialize Fulcio roots") } - return nil } diff --git a/pkg/engine/context/mock_context.go b/pkg/engine/context/mock_context.go index 99d3df7442..f12b33a7e7 100644 --- a/pkg/engine/context/mock_context.go +++ b/pkg/engine/context/mock_context.go @@ -41,8 +41,7 @@ func (ctx *MockContext) Query(query string) (interface{}, error) { var emptyResult interface{} // compile the query - _, err := jmespath.New(query) - if err != nil { + if _, err := jmespath.New(query); err != nil { return emptyResult, fmt.Errorf("invalid JMESPath query %s: %v", query, err) } diff --git a/pkg/engine/mutate/patch/buffer.go b/pkg/engine/mutate/patch/buffer.go index 4723e3e2d7..d9cd2a4e04 100644 --- a/pkg/engine/mutate/patch/buffer.go +++ b/pkg/engine/mutate/patch/buffer.go @@ -11,8 +11,8 @@ type buffer struct { // UnmarshalJSON writes the slice of bytes to an internal buffer func (buff buffer) UnmarshalJSON(b []byte) error { buff.Reset() - _, err := buff.Write(b) - if err != nil { + + if _, err := buff.Write(b); err != nil { return err } return nil diff --git a/pkg/engine/mutate/patch/strategicPreprocessing.go b/pkg/engine/mutate/patch/strategicPreprocessing.go index 01ab40b2a2..e68028aad0 100644 --- a/pkg/engine/mutate/patch/strategicPreprocessing.go +++ b/pkg/engine/mutate/patch/strategicPreprocessing.go @@ -296,10 +296,8 @@ func hasAnchor(key string) bool { } func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool { - ynode := pattern.YNode() - kind := ynode.Kind - - if kind == yaml.MappingNode { + ynode := pattern.YNode() // nolint:ifshort + if ynode.Kind == yaml.MappingNode { fields, err := pattern.Fields() if err != nil { return false @@ -317,10 +315,10 @@ func hasAnchors(pattern *yaml.RNode, isAnchor func(key string) bool) bool { } } } - } else if kind == yaml.ScalarNode { + } else if ynode.Kind == yaml.ScalarNode { v := ynode.Value return anchor.ContainsCondition(v) - } else if kind == yaml.SequenceNode { + } else if ynode.Kind == yaml.SequenceNode { elements, _ := pattern.Elements() for _, e := range elements { if hasAnchors(e, isAnchor) { diff --git a/pkg/engine/mutation.go b/pkg/engine/mutation.go index 197b4c70d4..1de90910ff 100644 --- a/pkg/engine/mutation.go +++ b/pkg/engine/mutation.go @@ -277,8 +277,7 @@ func buildSuccessMessage(r unstructured.Unstructured) string { return "mutated resource" } - ns := r.GetNamespace() - if ns == "" { + if r.GetNamespace() == "" { return fmt.Sprintf("mutated %s/%s", r.GetKind(), r.GetName()) }