Skip to content

Commit

Permalink
Merge pull request #4806 from koba1t/chore/update_golangci-lint_v1.49.0
Browse files Browse the repository at this point in the history
update golangci-lint version to v1.49.0
  • Loading branch information
k8s-ci-robot committed Sep 23, 2022
2 parents e62480d + 6ce230f commit 65aeefd
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 41 deletions.
8 changes: 5 additions & 3 deletions .golangci.yml
Expand Up @@ -14,7 +14,6 @@ linters:
- bodyclose
- contextcheck
# - cyclop
- deadcode
- depguard
- dogsled
- dupl
Expand Down Expand Up @@ -71,7 +70,6 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
# - stylecheck
- tagliatelle
- tenv
Expand All @@ -82,12 +80,16 @@ linters:
- unconvert
- unparam
- unused
- varcheck
# - varnamelen
- wastedassign
- whitespace
- wrapcheck
# - wsl
- asasalint
- usestdlibvars
- interfacebloat
- logrlint
- reassign

linters-settings:
dupl:
Expand Down
4 changes: 3 additions & 1 deletion Makefile-tools.mk
@@ -1,6 +1,8 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

GOLANGCI_LINT_VERSION=v1.49.0

MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin
Expand Down Expand Up @@ -28,7 +30,7 @@ uninstall-out-of-tree-tools:
rm -f $(MYGOBIN)/stringer

$(MYGOBIN)/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

$(MYGOBIN)/mdrip:
go install github.com/monopole/mdrip@v1.0.2
Expand Down
2 changes: 1 addition & 1 deletion api/krusty/namespaces_test.go
Expand Up @@ -692,7 +692,7 @@ resources:
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
}

// nolint:gosec
//nolint:gosec
const namespaceNeedInVarMyAppWithNamespace string = `
resources:
- elasticsearch-dev-service.yaml
Expand Down
2 changes: 1 addition & 1 deletion api/resmap/reswrangler_test.go
Expand Up @@ -301,7 +301,7 @@ func TestGetMatchingResourcesByCurrentId(t *testing.T) {
t.Fatalf("Expected single map entry but got %v", result)
}

// nolint:goconst
//nolint:goconst
tests := []struct {
name string
matcher IdMatcher
Expand Down
2 changes: 1 addition & 1 deletion api/types/helmchartargs.go
Expand Up @@ -71,7 +71,7 @@ type HelmChart struct {

// IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions.
// Defaults to 'false'.
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` // nolint: tagliatelle
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` //nolint: tagliatelle
}

// HelmChartArgs contains arguments to helm.
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/internal/commands/cmdxargs.go
Expand Up @@ -106,7 +106,7 @@ func (r *XArgsRunner) runE(c *cobra.Command, _ []string) error {
return fmt.Errorf("must specify -- before command")
}
r.Args = r.Args[cmdIndex:]
run := exec.Command(r.Args[0]) // nolint: gosec
run := exec.Command(r.Args[0]) //nolint: gosec

if len(r.Args) > 1 {
r.Args = r.Args[cmdIndex+1:]
Expand Down
6 changes: 3 additions & 3 deletions cmd/config/internal/commands/e2e/e2e_test.go
Expand Up @@ -719,7 +719,7 @@ metadata:
}

args := append([]string{"fn", "run", "."}, tt.args(binDir)...)
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) // nolint: gosec
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) //nolint: gosec
cmd.Dir = dir
var stdErr, stdOut bytes.Buffer
cmd.Stdout = &stdOut
Expand Down Expand Up @@ -761,7 +761,7 @@ func build() string {
panic(err)
}

build := exec.Command("go", "build", "-o", // nolint: gosec
build := exec.Command("go", "build", "-o", //nolint: gosec
filepath.Join(binDir, e2econtainerconfigBin))
build.Dir = "e2econtainerconfig"
build.Stdout = os.Stdout
Expand All @@ -773,7 +773,7 @@ func build() string {
panic(err)
}

build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin)) // nolint: gosec
build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin)) //nolint: gosec
build.Dir = filepath.Join("..", "..", "..", "kubectl-krm")
build.Stdout = os.Stdout
build.Stderr = os.Stderr
Expand Down
3 changes: 1 addition & 2 deletions cmd/config/internal/commands/grep.go
@@ -1,6 +1,5 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
//
package commands

import (
Expand Down Expand Up @@ -100,7 +99,7 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
r.Value = last[1]
}

r.Path = append(parts[:len(parts)-1], last[0]) // nolint:gocritic
r.Path = append(parts[:len(parts)-1], last[0]) //nolint:gocritic
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/pluginator/internal/krmfunction/funcwrapper/statik.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kyaml/filesys/fsnode_test.go
Expand Up @@ -903,7 +903,7 @@ func TestFileOps(t *testing.T) {
defer f.Close()

for {
buf := make([]byte, rand.Intn(10)) // nolint:gosec
buf := make([]byte, rand.Intn(10)) //nolint:gosec
n, err := f.Read(buf)
if err != nil && err != io.EOF {
t.Fatalf("unexpected error: %v", err)
Expand Down
42 changes: 21 additions & 21 deletions kyaml/filesys/util.go
Expand Up @@ -74,30 +74,30 @@ func PathJoin(incoming []string) string {
//
// E.g. if part == 'PEACH'
//
// OLD : NEW : POS
// --------------------------------------------------------
// {empty} : PEACH : irrelevant
// / : /PEACH : irrelevant
// pie : PEACH/pie : 0 (or negative)
// /pie : /PEACH/pie : 0 (or negative)
// raw : raw/PEACH : 1 (or larger)
// /raw : /raw/PEACH : 1 (or larger)
// a/nice/warm/pie : a/nice/warm/PEACH/pie : 3
// /a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3
// OLD : NEW : POS
// --------------------------------------------------------
// {empty} : PEACH : irrelevant
// / : /PEACH : irrelevant
// pie : PEACH/pie : 0 (or negative)
// /pie : /PEACH/pie : 0 (or negative)
// raw : raw/PEACH : 1 (or larger)
// /raw : /raw/PEACH : 1 (or larger)
// a/nice/warm/pie : a/nice/warm/PEACH/pie : 3
// /a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3
//
// * An empty part results in no change.
//
// * Absolute paths get their leading '/' stripped, treated like
// relative paths, and the leading '/' is re-added on output.
// The meaning of pos is intentionally the same in either absolute or
// relative paths; if it weren't, this function could convert absolute
// paths to relative paths, which is not desirable.
// - Absolute paths get their leading '/' stripped, treated like
// relative paths, and the leading '/' is re-added on output.
// The meaning of pos is intentionally the same in either absolute or
// relative paths; if it weren't, this function could convert absolute
// paths to relative paths, which is not desirable.
//
// * For robustness (liberal input, conservative output) Pos values that
// that are too small (large) to index the split filepath result in a
// prefix (postfix) rather than an error. Use extreme position values
// to assure a prefix or postfix (e.g. 0 will always prefix, and
// 9999 will presumably always postfix).
// - For robustness (liberal input, conservative output) Pos values that
// that are too small (large) to index the split filepath result in a
// prefix (postfix) rather than an error. Use extreme position values
// to assure a prefix or postfix (e.g. 0 will always prefix, and
// 9999 will presumably always postfix).
func InsertPathPart(path string, pos int, part string) string {
if part == "" {
return path
Expand All @@ -121,7 +121,7 @@ func InsertPathPart(path string, pos int, part string) string {
result := make([]string, len(parts)+1)
copy(result, parts[0:pos])
result[pos] = part
return PathJoin(append(result, parts[pos:]...)) // nolint: makezero
return PathJoin(append(result, parts[pos:]...)) //nolint: makezero
}

func IsHiddenFilePath(pattern string) bool {
Expand Down
2 changes: 1 addition & 1 deletion kyaml/fn/framework/function_definition.go
Expand Up @@ -82,7 +82,7 @@ type KRMFunctionVersion struct {

type KRMFunctionValidation struct {
// OpenAPIV3Schema is the OpenAPI v3 schema for an instance of the KRM function.
OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` // nolint: tagliatelle
OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` //nolint: tagliatelle
}

type KRMFunctionNames struct {
Expand Down
2 changes: 1 addition & 1 deletion kyaml/fn/runtime/exec/exec.go
Expand Up @@ -34,7 +34,7 @@ func (c *Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
}

func (c *Filter) Run(reader io.Reader, writer io.Writer) error {
cmd := exec.Command(c.Path, c.Args...) // nolint:gosec
cmd := exec.Command(c.Path, c.Args...) //nolint:gosec
cmd.Stdin = reader
cmd.Stdout = writer
cmd.Stderr = os.Stderr
Expand Down
7 changes: 5 additions & 2 deletions kyaml/fn/runtime/runtimeutil/functiontypes.go
Expand Up @@ -204,7 +204,7 @@ func (s *StorageMount) String() string {
func GetFunctionSpec(n *yaml.RNode) (*FunctionSpec, error) {
meta, err := n.GetMeta()
if err != nil {
return nil, nil
return nil, fmt.Errorf("failed to get ResourceMeta: %w", err)
}

fn, err := getFunctionSpecFromAnnotation(n, meta)
Expand Down Expand Up @@ -237,7 +237,10 @@ func getFunctionSpecFromAnnotation(n *yaml.RNode, meta yaml.ResourceMeta) (*Func
}
}
n, err := n.Pipe(yaml.Lookup("metadata", "configFn"))
if err != nil || yaml.IsMissingOrNull(n) {
if err != nil {
return nil, fmt.Errorf("failed to look up metadata.configFn: %w", err)
}
if yaml.IsMissingOrNull(n) {
return nil, nil
}
s, err := n.String()
Expand Down
19 changes: 18 additions & 1 deletion kyaml/runfn/runfn_test.go
Expand Up @@ -281,7 +281,23 @@ metadata:
out: []string{"gcr.io/example.com/image:v1.0.0"},
},

{name: "no function spec",
{
name: "no function spec",
in: []f{
{
explicitFunction: true,
value: `
apiVersion: example.com/v1alpha1
kind: ExampleFunction
metadata:
annotations:
foo: bar
`,
},
},
},
{
name: "invalid input object",
in: []f{
{
explicitFunction: true,
Expand All @@ -290,6 +306,7 @@ foo: bar
`,
},
},
error: "failed to get FunctionSpec: failed to get ResourceMeta: missing Resource metadata",
},

// Test
Expand Down

0 comments on commit 65aeefd

Please sign in to comment.