Repository: knative/pkg
Pull request #1731 (2020-09-22 15:58:16)

Enable unparam linter to catch unused parameters
Super useful linter to catch dead code hidden in parameters and return values.

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1731#" title="Author self-approved">markusthoemmes</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/knative/pkg/blob/master/OWNERS)~~ [markusthoemmes]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=h1) Report
> Merging [#1731](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=desc) into [master](https://codecov.io/gh/knative/pkg/commit/e4ecf702a3c4fc8c1dea4533662fd0600aa94331?el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/1731/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO)](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1731   +/-   ##
=======================================
  Coverage   67.64%   67.64%           
=======================================
  Files         226      226           
  Lines        9547     9547           
=======================================
  Hits         6458     6458           
  Misses       2718     2718           
  Partials      371      371           
```


| [Impacted Files](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [codegen/cmd/injection-gen/generators/packages.go](https://codecov.io/gh/knative/pkg/pull/1731/diff?src=pr&el=tree#diff-Y29kZWdlbi9jbWQvaW5qZWN0aW9uLWdlbi9nZW5lcmF0b3JzL3BhY2thZ2VzLmdv) | `0.00% <ø> (ø)` | |
| [metrics/config.go](https://codecov.io/gh/knative/pkg/pull/1731/diff?src=pr&el=tree#diff-bWV0cmljcy9jb25maWcuZ28=) | `81.14% <ø> (ø)` | |
| [webhook/conversion.go](https://codecov.io/gh/knative/pkg/pull/1731/diff?src=pr&el=tree#diff-d2ViaG9vay9jb252ZXJzaW9uLmdv) | `83.33% <ø> (ø)` | |
| [metrics/exporter.go](https://codecov.io/gh/knative/pkg/pull/1731/diff?src=pr&el=tree#diff-bWV0cmljcy9leHBvcnRlci5nbw==) | `78.26% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=footer). Last update [e4ecf70...f326f69](https://codecov.io/gh/knative/pkg/pull/1731?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

vagababov: 🎉 

Patch:
diff --git a/.golangci.yaml b/.golangci.yaml
index d569408fe..9d60f5792 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -10,6 +10,7 @@ linters:
     - gosec
     - prealloc
     - unconvert
+    - unparam
   disable:
     - errcheck
 
@@ -18,3 +19,4 @@ issues:
     - path: test # Excludes /test, *_test.go etc.
       linters:
         - gosec
+        - unparam
diff --git a/codegen/cmd/injection-gen/generators/packages.go b/codegen/cmd/injection-gen/generators/packages.go
index ab2ee1205..70e4eb7d1 100644
--- a/codegen/cmd/injection-gen/generators/packages.go
+++ b/codegen/cmd/injection-gen/generators/packages.go
@@ -572,7 +572,7 @@ func reconcilerPackages(basePackage string, groupPkgName string, gv clientgentyp
 	return vers
 }
 
-func versionDuckPackages(basePackage string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, boilerplate []byte, typesToGenerate []*types.Type, customArgs *informergenargs.CustomArgs) []generator.Package {
+func versionDuckPackages(basePackage string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, boilerplate []byte, typesToGenerate []*types.Type, _ *informergenargs.CustomArgs) []generator.Package {
 	packagePath := filepath.Join(basePackage, "ducks", groupPkgName, strings.ToLower(gv.Version.NonEmpty()))
 
 	vers := make([]generator.Package, 0, 2*len(typesToGenerate))
diff --git a/metrics/config.go b/metrics/config.go
index e62250fb0..fdf3cb855 100644
--- a/metrics/config.go
+++ b/metrics/config.go
@@ -28,7 +28,6 @@ import (
 	"time"
 
 	"go.opencensus.io/stats"
-	"go.uber.org/zap"
 	corev1 "k8s.io/api/core/v1"
 	"knative.dev/pkg/metrics/metricskey"
 )
@@ -174,7 +173,7 @@ func (mc *metricsConfig) record(ctx context.Context, mss []stats.Measurement, ro
 	return mc.recorder(ctx, mss, ros...)
 }
 
-func createMetricsConfig(ctx context.Context, ops ExporterOptions, logger *zap.SugaredLogger) (*metricsConfig, error) {
+func createMetricsConfig(ctx context.Context, ops ExporterOptions) (*metricsConfig, error) {
 	var mc metricsConfig
 
 	if ops.Domain == "" {
diff --git a/metrics/exporter.go b/metrics/exporter.go
index da5c510c9..a606c8ad2 100644
--- a/metrics/exporter.go
+++ b/metrics/exporter.go
@@ -135,7 +135,7 @@ func UpdateExporterFromConfigMapWithOpts(ctx context.Context, opts ExporterOptio
 // and updating the current exporter.
 func UpdateExporter(ctx context.Context, ops ExporterOptions, logger *zap.SugaredLogger) error {
 	// TODO(https://github.com/knative/pkg/issues/1273): check if ops.secrets is `nil` after new metrics plan lands
-	newConfig, err := createMetricsConfig(ctx, ops, logger)
+	newConfig, err := createMetricsConfig(ctx, ops)
 	if err != nil {
 		if getCurMetricsConfig() == nil {
 			// Fail the process if there doesn't exist an exporter.
diff --git a/webhook/conversion.go b/webhook/conversion.go
index 73cddd7a4..a54a6cb8e 100644
--- a/webhook/conversion.go
+++ b/webhook/conversion.go
@@ -36,7 +36,7 @@ type ConversionController interface {
 	Convert(context.Context, *apixv1.ConversionRequest) *apixv1.ConversionResponse
 }
 
-func conversionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c ConversionController) http.HandlerFunc {
+func conversionHandler(rootLogger *zap.SugaredLogger, _ StatsReporter, c ConversionController) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		logger := rootLogger
 		logger.Infof("Webhook ServeHTTP request=%#v", r)


Test patch:
diff --git a/metrics/config_test.go b/metrics/config_test.go
index d6c1f5e05..f5683e065 100644
--- a/metrics/config_test.go
+++ b/metrics/config_test.go
@@ -536,7 +536,7 @@ func TestGetMetricsConfig(t *testing.T) {
 	ctx := context.Background()
 	for _, test := range errorTests {
 		t.Run(test.name, func(t *testing.T) {
-			_, err := createMetricsConfig(ctx, test.ops, TestLogger(t))
+			_, err := createMetricsConfig(ctx, test.ops)
 			if err == nil || err.Error() != test.expectedErr {
 				t.Errorf("Wanted err: %v, got: %v", test.expectedErr, err)
 			}
@@ -546,7 +546,7 @@ func TestGetMetricsConfig(t *testing.T) {
 	successTestsInit()
 	for _, test := range successTests {
 		t.Run(test.name, func(t *testing.T) {
-			mc, err := createMetricsConfig(ctx, test.ops, TestLogger(t))
+			mc, err := createMetricsConfig(ctx, test.ops)
 			if err != nil {
 				t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err)
 			}
@@ -641,7 +641,7 @@ func TestGetMetricsConfig_fromEnv(t *testing.T) {
 			os.Setenv(test.varName, test.varValue)
 			defer os.Unsetenv(test.varName)
 
-			mc, err := createMetricsConfig(ctx, test.ops, TestLogger(t))
+			mc, err := createMetricsConfig(ctx, test.ops)
 			if err != nil {
 				t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err)
 			}
@@ -656,7 +656,7 @@ func TestGetMetricsConfig_fromEnv(t *testing.T) {
 			os.Setenv(test.varName, test.varValue)
 			defer os.Unsetenv(test.varName)
 
-			mc, err := createMetricsConfig(ctx, test.ops, TestLogger(t))
+			mc, err := createMetricsConfig(ctx, test.ops)
 			if mc != nil {
 				t.Errorf("Wanted no config, got %v", mc)
 			}
@@ -674,7 +674,7 @@ func TestIsNewExporterRequiredFromNilConfig(t *testing.T) {
 
 	for _, test := range successTests {
 		t.Run(test.name, func(t *testing.T) {
-			mc, err := createMetricsConfig(ctx, test.ops, TestLogger(t))
+			mc, err := createMetricsConfig(ctx, test.ops)
 			if err != nil {
 				t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err)
 			}
@@ -1052,7 +1052,7 @@ func TestStackdriverRecord(t *testing.T) {
 				Domain:    "knative.dev/internal/serving",
 				Component: "activator",
 			}
-			mc, err := createMetricsConfig(context.Background(), opts, TestLogger(t))
+			mc, err := createMetricsConfig(context.Background(), opts)
 			if err != nil {
 				t.Errorf("Expected valid config %+v, got error: %v\n", opts, err)
 			}
diff --git a/test/logstream/kubelogs.go b/test/logstream/kubelogs.go
index 592d3981d..ecd217329 100644
--- a/test/logstream/kubelogs.go
+++ b/test/logstream/kubelogs.go
@@ -110,7 +110,7 @@ func (k *kubelogs) watchPods(t test.TLegacy) {
 		t.Error("Logstream knative pod watch failed, logs might be missing", "error", err)
 		return
 	}
-	go func() error {
+	go func() {
 		watchedPods := sets.NewString()
 		for ev := range wi.ResultChan() {
 			p := ev.Object.(*corev1.Pod)
@@ -128,7 +128,6 @@ func (k *kubelogs) watchPods(t test.TLegacy) {
 				}
 			}
 		}
-		return nil
 	}()
 }