Skip to content

Commit 5709ff3

Browse files
enable default lints which were missing (#2413)
**Description of the change:** Ensure that all default ones will be enabled when we add all planned checks so far. See: https://github.com/golangci/golangci-lint#enabled-by-default-linters Add the following ones and fix the issues: * staticcheck * unused * gosimple Upgrade lint version as well.
1 parent 3b2256c commit 5709ff3

File tree

16 files changed

+29
-18
lines changed

16 files changed

+29
-18
lines changed

cmd/operator-sdk/test/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ func replaceImage(manifestPath, image string) error {
289289
if err != nil {
290290
return err
291291
}
292-
dep := &appsv1.Deployment{}
292+
var dep appsv1.Deployment
293293
switch o := obj.(type) {
294294
case *appsv1.Deployment:
295-
dep = o
295+
dep = *o
296296
default:
297297
return fmt.Errorf("error in replaceImage switch case; could not convert runtime.Object" +
298298
" to deployment")

hack/tests/check-lint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function fetch_go_linter {
77
header_text "Checking if golangci-lint is installed"
88
if ! is_installed golangci-lint; then
99
header_text "Installing golangci-lint"
10-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
10+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.22.2
1111
fi
1212
}
1313

@@ -62,4 +62,8 @@ golangci-lint run --disable-all \
6262
--enable=unparam \
6363
--enable=golint \
6464
--enable=lll \
65+
--enable=staticcheck \
66+
--enable=unused \
67+
--enable=gosimple \
6568
${LINTERS[@]}
69+

internal/olm/operator/tenancy.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ func parseInstallModeKV(raw string) (olmapiv1alpha1.InstallModeType, []string, e
7878
return "", nil, fmt.Errorf("installMode type string %q is not a valid installMode type", modeStr)
7979
}
8080
namespaces := []string{}
81-
for _, namespace := range strings.Split(strings.Trim(namespaceList, ","), ",") {
82-
namespaces = append(namespaces, namespace)
83-
}
81+
namespaces = append(namespaces, strings.Split(strings.Trim(namespaceList, ","), ",")...)
8482
return mode, namespaces, nil
8583
}
8684

internal/scaffold/entrypoint_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/operator-framework/operator-sdk/internal/util/diffutil"
2121
)
2222

23-
func EntrypointTest(t *testing.T) {
23+
func TestEntrypointTest(t *testing.T) {
2424
s, buf := setupScaffoldAndWriter()
2525
err := s.Execute(appConfig, &Entrypoint{})
2626
if err != nil {
@@ -46,5 +46,4 @@ if ! whoami &>/dev/null; then
4646
fi
4747
4848
exec ${OPERATOR} $@
49-
5049
`

internal/scaffold/olm-catalog/csv_updaters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func depHasOLMNamespaces(dep appsv1.Deployment) bool {
203203
// Something is wrong with the deployment manifest, not with CLI inputs.
204204
log.Fatalf("Marshal Deployment spec: %v", err)
205205
}
206-
return bytes.Index(b, []byte(olmTNMeta)) != -1
206+
return bytes.Contains(b, []byte(olmTNMeta))
207207
}
208208

209209
type descSorter []olmapiv1alpha1.CRDDescription

internal/scaffold/scaffold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func validateBoilerplateBytes(b []byte) error {
9898
}
9999
var tb []byte
100100
tb, cb = bytes.TrimSpace(b), bytes.TrimSpace(cb)
101-
if bytes.Compare(tb, cb) != 0 {
101+
if !bytes.Equal(tb, cb) {
102102
return fmt.Errorf(`boilerplate contains text other than comments:\n"%s"\n`, tb)
103103
}
104104
return nil

internal/scaffold/usersetup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/operator-framework/operator-sdk/internal/util/diffutil"
2121
)
2222

23-
func UserSetupTest(t *testing.T) {
23+
func TestUserSetup(t *testing.T) {
2424
s, buf := setupScaffoldAndWriter()
2525
err := s.Execute(appConfig, &UserSetup{})
2626
if err != nil {

internal/scorecard/plugins/olm_tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (t *CRDsHaveResourcesTest) Run(ctx context.Context) *schelpers.TestResult {
313313
break
314314
}
315315
}
316-
if foundResource == false {
316+
if !foundResource {
317317
missingResources = append(missingResources, fmt.Sprintf("%s/%s",
318318
resource.Kind, resource.Version))
319319
}

internal/scorecard/scorecard_output.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ func (cfg Config) combinePluginOutput(pluginOutputs []scapiv1alpha2.
6060
output := scapiv1alpha2.ScorecardOutput{}
6161
output.Results = make([]scapiv1alpha2.ScorecardTestResult, 0)
6262
for _, v := range pluginOutputs {
63-
for _, r := range v.Results {
64-
output.Results = append(output.Results, r)
65-
}
63+
output.Results = append(output.Results, v.Results...)
6664
}
6765

6866
if cfg.OutputFormat == JSONOutputFormat {

internal/util/k8sutil/k8sutil.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func GetDisplayName(name string) string {
8787
for j, r := range word {
8888
if unicode.IsUpper(r) {
8989
if j > 0 && !unicode.IsUpper(rune(word[j-1])) {
90-
temp = temp[0:j+o] + " " + temp[j+o:len(temp)]
90+
index := j + o
91+
temp = temp[0:index] + " " + temp[index:]
9192
o++
9293
}
9394
}

pkg/ansible/events/log_events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (l loggingEventHandler) Handle(ident string, u *unstructured.Unstructured,
100100
func (l loggingEventHandler) logAnsibleStdOut(e eventapi.JobEvent) {
101101
fmt.Printf("\n--------------------------- Ansible Task StdOut -------------------------------\n")
102102
if e.Event != eventapi.EventPlaybookOnTaskStart {
103-
fmt.Printf(fmt.Sprintf("\n TASK [%v] ******************************** \n", e.EventData["task"]))
103+
fmt.Printf("\n TASK [%v] ******************************** \n", e.EventData["task"])
104104
}
105105
fmt.Println(e.StdOut)
106106
fmt.Printf("\n-------------------------------------------------------------------------------\n")

pkg/ansible/proxy/proxy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ type apiResources struct {
311311
func (a *apiResources) resetResources() error {
312312
a.mu.Lock()
313313
defer a.mu.Unlock()
314+
315+
// TODO(camilamacedo86): Fix deprecation
316+
// SA1019: a.discoveryClient.ServerResources is deprecated: use ServerGroupsAndResources instead. (staticcheck)
317+
// nolint: staticcheck
314318
apisResourceList, err := a.discoveryClient.ServerResources()
315319
if err != nil {
316320
return err

pkg/ansible/watches/watches_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestLoad(t *testing.T) {
109109

110110
tmpl, err := template.ParseFiles("testdata/valid.yaml.tmpl")
111111
if err != nil {
112+
t.Fatalf("Unable to parse template: %v", err)
112113
}
113114
f, err := os.Create("testdata/valid.yaml")
114115
if err != nil {

pkg/k8sutil/k8sutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func GetOperatorName() (string, error) {
9191
// ResourceExists returns true if the given resource kind exists
9292
// in the given api groupversion
9393
func ResourceExists(dc discovery.DiscoveryInterface, apiGroupVersion, kind string) (bool, error) {
94+
// TODO(camilamacedo86): fix deprecation
95+
// SA1019: dc.ServerResources is deprecated: use ServerGroupsAndResources instead. (staticcheck)
96+
// nolint:staticcheck
9497
apiLists, err := dc.ServerResources()
9598
if err != nil {
9699
return false, err

pkg/kube-metrics/uclient.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func getAPIResource(cfg *rest.Config, apiVersion, kind string) (*metav1.APIResou
5757
return nil, nil, err
5858
}
5959

60+
// TODO(camilamacedo86): fix deprecation
61+
// nolint:staticcheck
62+
// SA1019: kclient.Discovery().ServerResources is deprecated: use ServerGroupsAndResources instead. (staticcheck)
6063
apiResourceLists, err := kclient.Discovery().ServerResources()
6164
if err != nil {
6265
return nil, nil, err

pkg/tls/tls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func getCASecretAndConfigMapInCluster(kubeClient kubernetes.Interface, name,
332332
return nil, nil, fmt.Errorf("expect either both ca configmap and secret both exist or not exist, "+
333333
" but got hasCAConfigmap==%v and hasCASecret==%v", hasConfigMap, hasSecret)
334334
}
335-
if hasConfigMap == false {
335+
if !hasConfigMap {
336336
return nil, nil, nil
337337
}
338338
return se, cm, nil

0 commit comments

Comments
 (0)