diff --git a/.golangci.yml b/.golangci.yml index a95363f..c32c072 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,11 +34,9 @@ linters-settings: - wrapperFunc - importShadow # not important for now - unnamedResult # not important - - commentedOutCode - - nestingReduce gocyclo: min-complexity: 15 - goimports: + goimports: {} golint: min-confidence: 0 gofmt: @@ -47,9 +45,9 @@ linters-settings: settings: mnd: # don't include the "operation" and "assign" - checks: argument,case,condition,return + checks: [argument, case, condition, return] govet: - check-shadowing: false + check-shadowing: true settings: printf: funcs: @@ -62,7 +60,7 @@ linters-settings: line-length: 140 maligned: suggest-new: true - misspell: + misspell: {} nolintlint: allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) allow-unused: false # report any unused nolint directives @@ -77,18 +75,13 @@ linters: - bodyclose - deadcode - depguard -# - dogsled - - dupl - errcheck -# - funlen -# - goconst - gofmt - goimports - goprintffuncname - gosec - gosimple - ineffassign -# - interfacer (This tool is deprecated) - misspell - nakedret - rowserrcheck @@ -99,52 +92,31 @@ linters: - unparam - unused - varcheck - - golint + - revive - gocritic - govet -# - lll -# - gocyclo -# - nestif - # don't enable: - # - testpackage - # - gochecknoinits - # - stylecheck - # - lll - # - govet - # - whitespace - # - exhaustive (TODO: enable after next release; current release at time of writing is v1.27) - # - gochecknoglobals - # - gocognit - # - godot - # - godox - # - goerr113 - # - maligned - # - prealloc - # - wsl - # - nolintlint - # - gomnd - # - scopelint + - dupl issues: # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: -# - path: _test\.go -# linters: -# - gomnd -# https://github.com/go-critic/go-critic/issues/926 + # - path: _test\.go + # linters: + # - gomnd + # https://github.com/go-critic/go-critic/issues/926 - linters: - gocritic text: "unnecessaryDefer:" + exclude: + - 'shadow: declaration of "err" shadows declaration at' max-same-issues: 0 - + run: + timeout: 30m skip-dirs: - - test/testdata_etc - - internal/cache - - internal/renameio - - internal/robustio + - cmd/docs # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration service: - golangci-lint-version: 1.29.x # use the fixed version to not introduce new linters unexpectedly + golangci-lint-version: 1.42.x # use the fixed version to not introduce new linters unexpectedly prepare: - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index f54b683..f195747 100755 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -26,11 +26,17 @@ spec: resources: {} - name: build-make-linux resources: {} + - image: golangci/golangci-lint:v1.42.1-alpine + name: make-lint + resources: {} + script: | + #!/bin/sh + golangci-lint run - name: build-make-test resources: {} - name: build-container-build resources: {} podTemplate: {} serviceAccountName: tekton-bot - timeout: 240h0m0s + timeout: 1h0m0s status: {} diff --git a/Makefile b/Makefile index 62f4127..2e36498 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ORG := jenkins-x-plugins ORG_REPO := $(ORG)/$(NAME) RELEASE_ORG_REPO := $(ORG_REPO) ROOT_PACKAGE := github.com/$(ORG_REPO) -GO_VERSION := 1.13 +GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go) BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown') diff --git a/cmd/app/main.go b/cmd/app/main.go index ae8ee30..c0cf7fa 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -1,10 +1,9 @@ +//nolint:gofmt,goimports // +build !windows package app -import ( - "github.com/jenkins-x-plugins/jx-admin/pkg/cmd" -) +import "github.com/jenkins-x-plugins/jx-admin/pkg/cmd" // Run runs the command, if args are not nil they will be set on the command func Run(args []string) error { diff --git a/hack/linter.sh b/hack/linter.sh index fa3b754..cdeceac 100755 --- a/hack/linter.sh +++ b/hack/linter.sh @@ -11,11 +11,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if ! [ -x "$(command -v golangci-lint)" ]; then echo "Installing GolangCI-Lint" - ${DIR}/install_golint.sh -b $GOPATH/bin v1.31.0 + ${DIR}/install_golint.sh -b $GOPATH/bin v1.42.1 fi export GO111MODULE=on golangci-lint run \ - --timeout 30m \ --verbose \ --build-tags build diff --git a/pkg/bootjobs/bootjobs.go b/pkg/bootjobs/bootjobs.go index 4df70aa..b67ec67 100644 --- a/pkg/bootjobs/bootjobs.go +++ b/pkg/bootjobs/bootjobs.go @@ -2,18 +2,19 @@ package bootjobs import ( "context" + "sort" + "strings" + "github.com/jenkins-x/jx-helpers/v3/pkg/stringhelpers" "github.com/pkg/errors" batchv1 "k8s.io/api/batch/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "sort" - "strings" ) // GetSortedJobs gets the boot jobs with an optional commit sha filter -func GetSortedJobs(client kubernetes.Interface, ns string, selector string, commitSHA string) ([]batchv1.Job, error) { +func GetSortedJobs(client kubernetes.Interface, ns, selector, commitSHA string) ([]batchv1.Job, error) { jobList, err := client.BatchV1().Jobs(ns).List(context.TODO(), metav1.ListOptions{ LabelSelector: selector, }) @@ -24,7 +25,8 @@ func GetSortedJobs(client kubernetes.Interface, ns string, selector string, comm answer := jobList.Items if commitSHA != "" { var filtered []batchv1.Job - for _, job := range answer { + for k := range answer { + job := answer[k] labels := job.Labels if labels != nil { sha := labels[LabelCommitSHA] diff --git a/pkg/cmd/create/create_test.go b/pkg/cmd/create/create_test.go index 491bc78..069d953 100644 --- a/pkg/cmd/create/create_test.go +++ b/pkg/cmd/create/create_test.go @@ -103,9 +103,9 @@ func TestCreate(t *testing.T) { outFile, err := ioutil.TempFile("", "") require.NoError(t, err, "failed to create tempo file") outFileName := outFile.Name() - args := append(tc.Args, "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--cluster", tc.Name, "--out", outFileName) - args = append(args, tc.Args...) - co.Args = args + tc.Args = append(tc.Args, "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--cluster", tc.Name, "--out", outFileName) + + co.Args = tc.Args co.Environment = tc.Environment if co.Environment == "" { co.Environment = "dev" diff --git a/pkg/cmd/joblog/joblog.go b/pkg/cmd/joblog/joblog.go index 9151604..a98ada1 100644 --- a/pkg/cmd/joblog/joblog.go +++ b/pkg/cmd/joblog/joblog.go @@ -166,14 +166,13 @@ See: https://jenkins-x.io/docs/v3/guides/operator/ if o.CommitSHA != "" { logger.Logger().Infof("waiting for boot Job pod with selector %s in namespace %s for commit SHA %s...", info(selector), info(ns), info(o.CommitSHA)) - } else { logger.Logger().Infof("waiting for boot Job pod with selector %s in namespace %s...", info(selector), info(ns)) } return nil } -func (o *Options) waitForActiveJob(client kubernetes.Interface, ns string, selector string, info func(a ...interface{}) string, containerName string) error { +func (o *Options) waitForActiveJob(client kubernetes.Interface, ns, selector string, info func(a ...interface{}) string, containerName string) error { job, err := o.waitForLatestJob(client, ns, selector) if err != nil { return errors.Wrapf(err, "failed to wait for active Job in namespace %s with selector %v", ns, selector) @@ -184,7 +183,7 @@ func (o *Options) waitForActiveJob(client kubernetes.Interface, ns string, selec return o.viewActiveJobLog(client, ns, selector, containerName, job) } -func (o *Options) viewActiveJobLog(client kubernetes.Interface, ns string, selector string, containerName string, job *batchv1.Job) error { +func (o *Options) viewActiveJobLog(client kubernetes.Interface, ns, selector, containerName string, job *batchv1.Job) error { var foundPods []string for { complete, pod, err := o.waitForJobCompleteOrPodRunning(client, ns, selector, job.Name) @@ -233,7 +232,7 @@ func (o *Options) viewActiveJobLog(client kubernetes.Interface, ns string, selec } } -func (o *Options) viewJobLog(client kubernetes.Interface, ns string, selector string, containerName string, job *batchv1.Job) error { +func (o *Options) viewJobLog(client kubernetes.Interface, ns, selector, containerName string, job *batchv1.Job) error { opts := metav1.ListOptions{ LabelSelector: "job-name=" + job.Name, } @@ -436,7 +435,7 @@ func (o *Options) checkIfJobComplete(client kubernetes.Interface, ns, name strin return false, job, nil } -func (o *Options) pickJobToLog(client kubernetes.Interface, ns string, selector string, jobs []batchv1.Job) error { +func (o *Options) pickJobToLog(client kubernetes.Interface, ns, selector string, jobs []batchv1.Job) error { var names []string m := map[string]*batchv1.Job{} for i := range jobs { @@ -462,7 +461,7 @@ func (o *Options) pickJobToLog(client kubernetes.Interface, ns string, selector func toJobName(j *batchv1.Job, number int) string { status := JobStatus(j) - d := time.Now().Sub(j.CreationTimestamp.Time).Round(time.Minute) + d := time.Since(j.CreationTimestamp.Time).Round(time.Minute) return fmt.Sprintf("#%d started %s %s", number, d.String(), status) } diff --git a/pkg/reqhelpers/helpers.go b/pkg/reqhelpers/helpers.go index 5bd2a07..c2a7a1c 100644 --- a/pkg/reqhelpers/helpers.go +++ b/pkg/reqhelpers/helpers.go @@ -200,8 +200,8 @@ func applyDefaults(cmd *cobra.Command, r *jxcore.RequirementsConfig, flags *Requ } gitKind := r.Cluster.GitKind - gitKinds := append(giturl.KindGits, "fake") - if gitKind != "" && stringhelpers.StringArrayIndex(gitKinds, gitKind) < 0 { + giturl.KindGits = append(giturl.KindGits, "fake") + if gitKind != "" && stringhelpers.StringArrayIndex(giturl.KindGits, gitKind) < 0 { return nil, options.InvalidOption("git-kind", gitKind, giturl.KindGits) }