Skip to content

Commit

Permalink
Address new linter complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
KnVerey committed Mar 31, 2022
1 parent b368b34 commit 14947e4
Show file tree
Hide file tree
Showing 77 changed files with 220 additions and 210 deletions.
33 changes: 21 additions & 12 deletions .golangci-kustomize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ linters:
- bodyclose
- deadcode
- depguard
# - dogsled
- dogsled
- dupl
# - errcheck
# - funlen
# - gochecknoinits
# - errcheck
- exportloopref
# - funlen
- gochecknoinits
- goconst
# - gocritic
- gocritic
- gocyclo
- gofmt
- goimports
Expand All @@ -24,19 +25,17 @@ linters:
- lll
- misspell
- nakedret
- nolintlint
- revive
# - scopelint
- staticcheck
- structcheck
# stylecheck demands that acronyms not be treated as words
# in camelCase, so JsonOp become JSONOp, etc. Yuck.
# - stylecheck
# - stylecheck # seems redundant with revive, which replaced golint
- typecheck
- unconvert
- unparam
- unused
- varcheck
# - whitespace
- whitespace

linters-settings:
dupl:
Expand All @@ -45,5 +44,15 @@ linters-settings:
line-length: 170
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.85
revive:
rules:
- name: var-naming
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList

issues:
exclude-rules:
- linters:
- revive
text: "don't use leading"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@ clean-kustomize-external-go-plugin:
lint-kustomize: $(MYGOBIN)/golangci-lint-kustomize $(builtinplugins)
cd api; $(MYGOBIN)/golangci-lint-kustomize \
-c ../.golangci-kustomize.yml \
--path-prefix api \
run ./...
cd kustomize; $(MYGOBIN)/golangci-lint-kustomize \
-c ../.golangci-kustomize.yml \
--path-prefix kustomize \
run ./...
cd cmd/pluginator; $(MYGOBIN)/golangci-lint-kustomize \
-c ../../.golangci-kustomize.yml \
--path-prefix cmd/pluginator \
run ./...

# Used to add non-default compilation flags when experimenting with
Expand Down
2 changes: 1 addition & 1 deletion api/filters/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ spec:
t.Run(tn, func(t *testing.T) {
filter := tc.filter
filter.WithMutationTracker(tc.setEntryCallback)
filter.FsSlice = append(annosFs, tc.fsslice...)
filter.FsSlice = append(annosFs, tc.fsslice...) //nolint:gocritic
if !assert.Equal(t,
strings.TrimSpace(tc.expectedOutput),
strings.TrimSpace(filtertest_test.RunFilter(t, tc.input, filter))) {
Expand Down
2 changes: 1 addition & 1 deletion api/filters/iampolicygenerator/iampolicygenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ metadata:
f.IAMPolicyGenerator.KubernetesService.Name)

if f.IAMPolicyGenerator.Namespace != "" {
input = input + fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
input += fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
}

sa, err := yaml.Parse(input)
Expand Down
4 changes: 1 addition & 3 deletions api/filters/imagetag/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func (f findFieldsFilter) walk(node *yaml.RNode) error {
return nil
})
case yaml.SequenceNode:
return node.VisitElements(func(n *yaml.RNode) error {
return f.walk(n)
})
return node.VisitElements(f.walk)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions api/filters/imagetag/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ func (u imageTagUpdater) SetImageValue(rn *yaml.RNode) error {
}

// overriding tag or digest will replace both original tag and digest values
if u.ImageTag.NewTag != "" && u.ImageTag.Digest != "" {
switch {
case u.ImageTag.NewTag != "" && u.ImageTag.Digest != "":
tag = u.ImageTag.NewTag
digest = u.ImageTag.Digest
} else if u.ImageTag.NewTag != "" {
case u.ImageTag.NewTag != "":
tag = u.ImageTag.NewTag
digest = ""
} else if u.ImageTag.Digest != "" {
case u.ImageTag.Digest != "":
tag = ""
digest = u.ImageTag.Digest
}
Expand Down
1 change: 0 additions & 1 deletion api/filters/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, gvk resid.Gvk) error {
}

return ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString)(node)

})

return err
Expand Down
2 changes: 1 addition & 1 deletion api/filters/namespace/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestNamespace_Filter(t *testing.T) {
test := tests[i]
test.filter.WithMutationTracker(test.mutationTracker)
t.Run(test.name, func(t *testing.T) {
test.filter.FsSlice = append(config.NameSpace, test.fsslice...)
test.filter.FsSlice = append(config.NameSpace, test.fsslice...) //nolint:gocritic
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(
Expand Down
1 change: 0 additions & 1 deletion api/filters/refvar/refvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var makeMf = func(theMap map[string]interface{}) MappingFunc {
}

func TestFilter(t *testing.T) {

testCases := map[string]struct {
input string
expected string
Expand Down
8 changes: 4 additions & 4 deletions api/filters/replacement/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type Filter struct {

// Filter replaces values of targets with values from sources
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
for _, r := range f.Replacements {
for i, r := range f.Replacements {
if r.Source == nil || r.Targets == nil {
return nil, fmt.Errorf("replacements must specify a source and at least one target")
}
value, err := getReplacement(nodes, &r)
value, err := getReplacement(nodes, &f.Replacements[i])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -60,8 +60,8 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targets []*types.T
}

// filter targets by matching resource IDs
for _, id := range ids {
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &id) {
for i, id := range ids {
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &ids[i]) {
err := applyToNode(n, value, t)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion api/internal/accumulator/namereferencetransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func debug(fMap filterMap) {
// 'spec/scaleTargetRef/name' field. Return a filter that can do that.
func (t *nameReferenceTransformer) determineFilters(
resources []*resource.Resource) (fMap filterMap) {

// We cache the resource OrgId values because they don't change and otherwise are very visible in a memory pprof
resourceOrgIds := make([]resid.ResId, len(resources))
for i, resource := range resources {
Expand Down
1 change: 0 additions & 1 deletion api/internal/accumulator/resaccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func (ra *ResAccumulator) findVarValueFromResources(v types.Var) (interface{}, e
for _, res := range ra.resMap.Resources() {
for _, varName := range res.GetRefVarNames() {
if varName == v.Name {
//nolint: staticcheck
s, err := res.GetFieldValue(v.FieldRef.FieldPath)
if err != nil {
return "", fmt.Errorf(
Expand Down
11 changes: 5 additions & 6 deletions api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func (x *RepoSpec) Cleaner(fSys filesys.FileSystem) func() error {
return func() error { return fSys.RemoveAll(x.Dir.String()) }
}

// NewRepoSpecFromUrl parses git-like urls.
// NewRepoSpecFromURL parses git-like urls.
// From strings like git@github.com:someOrg/someRepo.git or
// https://github.com/someOrg/someRepo?ref=someHash, extract
// the parts.
func NewRepoSpecFromUrl(n string) (*RepoSpec, error) {
func NewRepoSpecFromURL(n string) (*RepoSpec, error) {
if filepath.IsAbs(n) {
return nil, fmt.Errorf("uri looks like abs path: %s", n)
}
host, orgRepo, path, gitRef, gitSubmodules, suffix, gitTimeout := parseGitUrl(n)
host, orgRepo, path, gitRef, gitSubmodules, suffix, gitTimeout := parseGitURL(n)
if orgRepo == "" {
return nil, fmt.Errorf("url lacks orgRepo: %s", n)
}
Expand All @@ -108,9 +108,8 @@ const (
// From strings like git@github.com:someOrg/someRepo.git or
// https://github.com/someOrg/someRepo?ref=someHash, extract
// the parts.
func parseGitUrl(n string) (
func parseGitURL(n string) (
host string, orgRepo string, path string, gitRef string, gitSubmodules bool, gitSuff string, gitTimeout time.Duration) {

if strings.Contains(n, gitDelimiter) {
index := strings.Index(n, gitDelimiter)
// Adding _git/ to host
Expand Down Expand Up @@ -229,7 +228,7 @@ func parseHostSpec(n string) (string, string) {
if strings.HasSuffix(host, p) {
i := strings.Index(n, "/")
if i > -1 {
host = host + n[0:i+1]
host += n[0 : i+1]
n = n[i+1:]
}
break
Expand Down
10 changes: 5 additions & 5 deletions api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var hostNamesRawAndNormalized = [][]string{
{"git@github.com/", "git@github.com:"},
}

func makeUrl(hostFmt, orgRepo, path, href string) string {
func makeURL(hostFmt, orgRepo, path, href string) string {
if len(path) > 0 {
orgRepo = filepath.Join(orgRepo, path)
}
Expand All @@ -56,8 +56,8 @@ func TestNewRepoSpecFromUrl(t *testing.T) {
for _, orgRepo := range orgRepos {
for _, pathName := range pathNames {
for _, hrefArg := range hrefArgs {
uri := makeUrl(hostRaw, orgRepo, pathName, hrefArg)
rs, err := NewRepoSpecFromUrl(uri)
uri := makeURL(hostRaw, orgRepo, pathName, hrefArg)
rs, err := NewRepoSpecFromURL(uri)
if err != nil {
t.Errorf("problem %v", err)
}
Expand Down Expand Up @@ -99,7 +99,7 @@ var badData = [][]string{

func TestNewRepoSpecFromUrlErrors(t *testing.T) {
for _, tuple := range badData {
_, err := NewRepoSpecFromUrl(tuple[0])
_, err := NewRepoSpecFromURL(tuple[0])
if err == nil {
t.Error("expected error")
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) {
}
for tn, tc := range testcases {
t.Run(tn, func(t *testing.T) {
rs, err := NewRepoSpecFromUrl(tc.input)
rs, err := NewRepoSpecFromURL(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.cloneSpec, rs.CloneSpec(), "cloneSpec mismatch")
assert.Equal(t, tc.absPath, rs.AbsPath(), "absPath mismatch")
Expand Down
2 changes: 1 addition & 1 deletion api/internal/plugins/builtinhelpers/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (

var stringToBuiltinPluginTypeMap map[string]BuiltinPluginType

func init() {
func init() { //nolint:gochecknoinits
stringToBuiltinPluginTypeMap = makeStringToBuiltinPluginTypeMap()
}

Expand Down
1 change: 0 additions & 1 deletion api/internal/plugins/execplugin/execplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ metadata:
`
if expected != string(p.Cfg()) {
t.Fatalf("expected cfg '%s', got '%s'", expected, string(p.Cfg()))

}
if len(p.Args()) != 6 {
t.Fatalf("unexpected arg len %d, %#v", len(p.Args()), p.Args())
Expand Down
4 changes: 2 additions & 2 deletions api/internal/plugins/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {
"TrUe",
"potato",
}
for i, c := range cases {
for i := range cases {
name := fmt.Sprintf("test%d", i)
in := resmap.New()
err := in.Append(makeConfigMap(rf, name, "", &c))
err := in.Append(makeConfigMap(rf, name, "", &cases[i]))
require.NoError(t, err)
_, err = UpdateResourceOptions(in)
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion api/krusty/basic_io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
`)
}

//test for https://github.com/kubernetes-sigs/kustomize/issues/3812#issuecomment-862339267
// test for https://github.com/kubernetes-sigs/kustomize/issues/3812#issuecomment-862339267
func TestBasicIO3812(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
Expand Down
1 change: 0 additions & 1 deletion api/krusty/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ metadata:
}

func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) {

th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
configMapGenerator:
Expand Down
16 changes: 8 additions & 8 deletions api/krusty/diamondcomposition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const container = `{ "image": "my-image", "livenessProbe": { "httpGet" : {"path"
const patchJsonAddProbe = `[{"op": "replace", "path": "/spec/template/spec/containers/0", "value": ` +
container + `}]`

const patchDnsPolicy = `
const patchDNSPolicy = `
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -44,7 +44,7 @@ spec:
spec:
dnsPolicy: ClusterFirst
`
const patchJsonDnsPolicy = `[{"op": "add", "path": "/spec/template/spec/dnsPolicy", "value": "ClusterFirst"}]`
const patchJsonDNSPolicy = `[{"op": "add", "path": "/spec/template/spec/dnsPolicy", "value": "ClusterFirst"}]`

const patchRestartPolicy = `
apiVersion: apps/v1
Expand Down Expand Up @@ -96,7 +96,7 @@ resources:
patchesStrategicMerge:
- dep-patch.yaml
`)
th.WriteF("dns/dep-patch.yaml", patchDnsPolicy)
th.WriteF("dns/dep-patch.yaml", patchDNSPolicy)
}

func writeRestartOverlay(th kusttest_test.Harness) {
Expand Down Expand Up @@ -209,7 +209,7 @@ patchesStrategicMerge:
- patchRestartPolicy.yaml
`)
th.WriteF("composite/patchRestartPolicy.yaml", patchRestartPolicy)
th.WriteF("composite/patchDnsPolicy.yaml", patchDnsPolicy)
th.WriteF("composite/patchDnsPolicy.yaml", patchDNSPolicy)
th.WriteF("composite/patchAddProbe.yaml", patchAddProbe)

m := th.Run("composite", th.MakeDefaultOptions())
Expand All @@ -220,7 +220,7 @@ func definePatchDirStructure(th kusttest_test.Harness) {
writeDeploymentBase(th)

th.WriteF("patches/patchRestartPolicy.yaml", patchRestartPolicy)
th.WriteF("patches/patchDnsPolicy.yaml", patchDnsPolicy)
th.WriteF("patches/patchDnsPolicy.yaml", patchDNSPolicy)
th.WriteF("patches/patchAddProbe.yaml", patchAddProbe)
}

Expand Down Expand Up @@ -368,7 +368,7 @@ func TestIssue1251_Plugins_Local(t *testing.T) {
writeDeploymentBase(th.Harness)

writeJsonTransformerPluginConfig(
th, "composite", "addDnsPolicy", patchJsonDnsPolicy)
th, "composite", "addDnsPolicy", patchJsonDNSPolicy)
writeJsonTransformerPluginConfig(
th, "composite", "addRestartPolicy", patchJsonRestartPolicy)
writeJsonTransformerPluginConfig(
Expand Down Expand Up @@ -417,7 +417,7 @@ resources:
- addProbeConfig.yaml
`)
writeJsonTransformerPluginConfig(
th, "patches", "addDnsPolicy", patchJsonDnsPolicy)
th, "patches", "addDnsPolicy", patchJsonDNSPolicy)
writeJsonTransformerPluginConfig(
th, "patches", "addRestartPolicy", patchJsonRestartPolicy)
writeJsonTransformerPluginConfig(
Expand All @@ -441,7 +441,7 @@ resources:
- addDnsPolicyConfig.yaml
`)
writeJsonTransformerPluginConfig(
th, "patches/addDnsPolicy", "addDnsPolicy", patchJsonDnsPolicy)
th, "patches/addDnsPolicy", "addDnsPolicy", patchJsonDNSPolicy)

th.WriteK("patches/addRestartPolicy", `
resources:
Expand Down
4 changes: 2 additions & 2 deletions api/krusty/disablenamesuffix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ metadata:
}

th.WriteK("/whatever",
strings.Replace(kustomizationContent,
strings.ReplaceAll(kustomizationContent,
"disableNameSuffixHash: false",
"disableNameSuffixHash: true", -1))
"disableNameSuffixHash: true"))
m = th.Run("/whatever", th.MakeDefaultOptions())
secret = findSecret(m, "")
if secret == nil {
Expand Down
Loading

0 comments on commit 14947e4

Please sign in to comment.