Skip to content

Enable variable shadowing check in govet linter #265

Open
@tuminoid

Description

@tuminoid

If we enable variable shadowing check in govet, we get a lot of errors. Variable shadowing can cause hard to debug issues.

diff --git a/.golangci.yaml b/.golangci.yaml
index a1014da..e9b2a0c 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -110,6 +110,9 @@ linters-settings:
   gocritic:
     enabled-tags:
     - experimental
+  govet:
+    enable:
+    - shadow
 issues:
   exclude-files:
   - "zz_generated.*\\.go$"

leads to

internal/controller/ironic_controller.go:129:19: shadow: declaration of "err" shadows declaration at line 107 (govet)
			parsedVersion, err := metal3api.ParseVersion(ironicConf.Status.InstalledVersion)
			               ^
pkg/ironic/ironic.go:172:14: shadow: declaration of "err" shadows declaration at line 159 (govet)
		jobStatus, err := ensureIronicUpgradeJob(cctx, resources, preUpgrade)
		           ^
INFO File cache stats: 2 entries of total size 16.8KiB 
INFO Memory: 577 samples, avg is 839.2MB, max is 4952.4MB 
INFO Execution took 58.153887653s                 
make: *** [Makefile:243: lint] Error 1

/kind ci
/help
/good-first-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/ciCategorizes issue or PR as related to CI or testing.triage/acceptedIndicates an issue is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions