From 977bc4e8b032a89d7c035fcc76ab61ccf71ce449 Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Thu, 27 Jan 2022 13:16:10 +0100 Subject: [PATCH 1/4] Enable super linters --- .github/linters/.golangci.yml | 42 ++++++++++ .github/linters/.yaml-lint.yml | 14 ++++ .github/workflows/linter.yml | 84 +++++++++++++++++++ controllers/node_label_sync_test.go | 3 +- .../controllers/sharedvolume/controller.go | 1 + 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .github/linters/.golangci.yml create mode 100644 .github/linters/.yaml-lint.yml create mode 100644 .github/workflows/linter.yml diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml new file mode 100644 index 00000000..e9c8fc1e --- /dev/null +++ b/.github/linters/.golangci.yml @@ -0,0 +1,42 @@ +--- +######################### +######################### +## Golang Linter rules ## +######################### +######################### + +# configure golangci-lint +# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +run: + skip-files: + - zz_generated* + - suite_test.go + timeout: 3m + +issues: + exclude-rules: + - path: _test\.go + linters: + - dupl + - gosec + - goconst + +linters: + disable: + - typecheck + enable: + - nilerr + - whitespace + - gofmt + - misspell + +linters-settings: + errcheck: + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: true + govet: + # report about shadowed variables + check-shadowing: false + gosimple: + checks: [ "-S1019" ] diff --git a/.github/linters/.yaml-lint.yml b/.github/linters/.yaml-lint.yml new file mode 100644 index 00000000..e1caa425 --- /dev/null +++ b/.github/linters/.yaml-lint.yml @@ -0,0 +1,14 @@ +extends: default + +rules: + line-length: disable + truthy: disable + brackets: disable + trailing-spaces: disable + document-start: disable + indentation: disable + comments: disable + comments-indentation: disable + colons: disable + empty-lines: disable + new-line-at-end-of-file: disable diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..0e0cd187 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,84 @@ +--- +################################# +################################# +## Super Linter GitHub Actions ## +################################# +################################# +name: Lint Full Codebase + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +############################# +# Start the job on all push # +############################# +on: [ push, pull_request ] + +############### +# Set the Job # +############### +jobs: + golangci: + name: Go Linter + runs-on: ubuntu-18.04 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - name: Deps + run: | + sudo apt update + sudo apt install -y build-essential + sudo apt install -y libdevmapper-dev + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - uses: actions/checkout@v2 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.42.1 + args: -c=".github/linters/.golangci.yml" + build: + # Name the Job + name: Super Linter (non-Go) + # Set the agent to run on + runs-on: ubuntu-latest + + ################## + # Load all steps # + ################## + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + ########################## + # Checkout the code base # + ########################## + - name: Checkout Code + uses: actions/checkout@v2 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 + + ################################ + # Run Linter against code base # + ################################ + - name: super-linter + uses: github/super-linter@v4 + env: + VALIDATE_ALL_CODEBASE: true + VALIDATE_MARKDOWN: true + VALIDATE_SHELL_SHFMT: true + VALIDATE_YAML: true + VALIDATE_BASH: true + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/controllers/node_label_sync_test.go b/controllers/node_label_sync_test.go index ee50481d..3daa7f1e 100644 --- a/controllers/node_label_sync_test.go +++ b/controllers/node_label_sync_test.go @@ -82,9 +82,10 @@ func SetupNodeLabelSyncTest(ctx context.Context, isStorageOS bool, createLabels // getCSIAnnotation is a helper to return a valid StorageOS CSI Driver annotation. func getCSIAnnotation() (string, string) { - driverMap, _ := json.Marshal(map[string]string{ + driverMap, err := json.Marshal(map[string]string{ provisioner.DriverName: uuid.New().String(), }) + Expect(err).NotTo(BeNil()) return provisioner.NodeDriverAnnotationKey, string(driverMap) } diff --git a/internal/controllers/sharedvolume/controller.go b/internal/controllers/sharedvolume/controller.go index bf29a350..092e29ea 100644 --- a/internal/controllers/sharedvolume/controller.go +++ b/internal/controllers/sharedvolume/controller.go @@ -152,6 +152,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err != nil { // Non StorageOS shared volume, nothing to do. r.log.Info("non StorageOS shared volume", "name", vol.Name) + //lint:ignore nilerr if non StorageOS nothing to do return ctrl.Result{}, nil } From 71303958727840d05cd9f47607f9a9211b21e334 Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Thu, 27 Jan 2022 14:13:13 +0100 Subject: [PATCH 2/4] Turn bash and markdown linters off --- .github/workflows/linter.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0e0cd187..82483ecd 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -76,9 +76,7 @@ jobs: uses: github/super-linter@v4 env: VALIDATE_ALL_CODEBASE: true - VALIDATE_MARKDOWN: true VALIDATE_SHELL_SHFMT: true VALIDATE_YAML: true - VALIDATE_BASH: true DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5c63a365bcf3635b0c1ee6c73e148633f5b3dfca Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Thu, 27 Jan 2022 15:33:07 +0100 Subject: [PATCH 3/4] Ignore errcheck in node label sync test --- api/v1/zz_generated.deepcopy.go | 1 - controllers/node_label_sync_test.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index aacb45f7..368d8c38 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/controllers/node_label_sync_test.go b/controllers/node_label_sync_test.go index 3daa7f1e..ab3f8f43 100644 --- a/controllers/node_label_sync_test.go +++ b/controllers/node_label_sync_test.go @@ -82,10 +82,10 @@ func SetupNodeLabelSyncTest(ctx context.Context, isStorageOS bool, createLabels // getCSIAnnotation is a helper to return a valid StorageOS CSI Driver annotation. func getCSIAnnotation() (string, string) { - driverMap, err := json.Marshal(map[string]string{ + //lint:ignore errcheck not needed + driverMap, _ := json.Marshal(map[string]string{ provisioner.DriverName: uuid.New().String(), }) - Expect(err).NotTo(BeNil()) return provisioner.NodeDriverAnnotationKey, string(driverMap) } From 08053043407c0c7cec8ff01c256a6ba6ff4fb8b4 Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Thu, 27 Jan 2022 15:37:12 +0100 Subject: [PATCH 4/4] Not ignore errcheck in node label sync test --- controllers/node_label_sync_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/controllers/node_label_sync_test.go b/controllers/node_label_sync_test.go index ab3f8f43..c2478e60 100644 --- a/controllers/node_label_sync_test.go +++ b/controllers/node_label_sync_test.go @@ -82,10 +82,12 @@ func SetupNodeLabelSyncTest(ctx context.Context, isStorageOS bool, createLabels // getCSIAnnotation is a helper to return a valid StorageOS CSI Driver annotation. func getCSIAnnotation() (string, string) { - //lint:ignore errcheck not needed - driverMap, _ := json.Marshal(map[string]string{ + driverMap, err := json.Marshal(map[string]string{ provisioner.DriverName: uuid.New().String(), }) + if err != nil { + println(err) + } return provisioner.NodeDriverAnnotationKey, string(driverMap) }