diff --git a/.github/workflows/code-health.yaml b/.github/workflows/code-health.yaml index 1a16b04f7..69790d4aa 100644 --- a/.github/workflows/code-health.yaml +++ b/.github/workflows/code-health.yaml @@ -50,9 +50,9 @@ jobs: go-version-file: 'cfn-resources/go.mod' cache: false # see https://github.com/golangci/golangci-lint-action/issues/807 - name: golangci-lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd with: - version: v1.60.3 # Also update GOLANGCI_VERSION variable in Makefile when updating this version + version: v2.0.2 # Also update GOLANGCI_VERSION variable in Makefile when updating this version working-directory: cfn-resources - name: actionlint run: | diff --git a/Makefile b/Makefile index af9f9ff13..8708cc4a0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ldXflags=github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLo ldXflagsD=github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLogLevel=debug MOCKERY_VERSION=v2.42.1 -GOLANGCI_VERSION=v1.60.3 # Also update golangci-lint GH action in code-health.yml when updating this version +GOLANGCI_VERSION=v2.0.2 # Also update golangci-lint GH action in code-health.yml when updating this version .PHONY: submit submit: diff --git a/cfn-resources/.golangci.yml b/cfn-resources/.golangci.yml index 237271830..fa727c17d 100644 --- a/cfn-resources/.golangci.yml +++ b/cfn-resources/.golangci.yml @@ -1,131 +1,107 @@ -linters-settings: - exhaustive: - default-signifies-exhaustive: true - - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - # cfn handlers generated automatically, below are exempted for the same - - hugeParam - - paramTypeCombine - govet: - enable-all: true - - revive: - # see https://github.com/mgechev/revive#available-rules for details. - ignore-generated-header: true - severity: warning - rules: - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: errorf - - name: exported - - name: indent-error-flow - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: empty-block - - name: superfluous-else - - name: struct-tag - # Too many unusued parameters, skipping this check for now - #- name: unused-parameter - - name: unreachable-code - - name: redefines-builtin-id - misspell: - locale: US - ignore-words: - - cancelled - lll: - # Default is 120. '\t' is counted as 1 character. - # set our project to 500, as we are adding open api field description in the schema. - # also, for anyone using vscode, use the following configs: - # "rewrap.wrappingColumn": 500 ... requires the rewrap plugin - # "editor.rulers": [500] - line-length: 500 - nestif: - # minimal complexity of if statements to report, 5 by default - min-complexity: 7 - mnd: - checks: - - case - - operation - - return - funlen: - lines: 360 - statements: 120 +version: "2" +run: + modules-download-mode: readonly + tests: true linters: - disable-all: true + default: none enable: + - copyloopvar - dogsled - errcheck + - exhaustive - funlen - gocritic - - gofmt - - goimports - - revive - - mnd - goprintffuncname - gosec - - gosimple - govet - ineffassign - lll + - makezero - misspell + - mnd - nakedret + - noctx - nolintlint + - revive - rowserrcheck - - copyloopvar - staticcheck - - stylecheck - - typecheck + - testifylint + - testpackage + - thelper - unconvert - unused - whitespace - - thelper - - testifylint - - exhaustive - - makezero - - noctx - - tenv - - testpackage - - # don't enable: - # - deadcode - # - varcheck - # - structcheck - # - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false] - # - gocyclo # we already have funlen lint - # - dupl # we have a lot of duplicate test cases - # - gochecknoinits # we need the init function for the provider - # - gochecknoglobals # we need some global variables - # - unparam # Forces to create global variables when one variable is repeated in different functions - # - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it - # - goconst - # - gocognit -issues: - exclude: - - declaration of ".*" shadows declaration at line .* -run: - timeout: 10m - tests: true - build-tags: - - integration - modules-download-mode: readonly + settings: + exhaustive: + default-signifies-exhaustive: true + funlen: + lines: 360 + statements: 120 + gocritic: + disabled-checks: + - hugeParam + - paramTypeCombine + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + govet: + enable-all: true + lll: + line-length: 500 + misspell: + locale: US + ignore-rules: + - cancelled + mnd: + checks: + - case + - operation + - return + nestif: + min-complexity: 7 + revive: + severity: warning + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: errorf + - name: exported + - name: indent-error-flow + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: struct-tag + - name: unreachable-code + - name: redefines-builtin-id + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - path: (.+)\.go$ + text: declaration of ".*" shadows declaration at line .* +formatters: + enable: + - gofmt + - goimports diff --git a/cfn-resources/cluster/cmd/resource/mappings_test.go b/cfn-resources/cluster/cmd/resource/mappings_test.go index b9d518ab1..7cb3aba9c 100644 --- a/cfn-resources/cluster/cmd/resource/mappings_test.go +++ b/cfn-resources/cluster/cmd/resource/mappings_test.go @@ -113,7 +113,7 @@ func TestNewHardwareSpec(t *testing.T) { hardwareSpec := resource.NewHardwareSpec(&tc.spec) hwSpecJSON, err := json.Marshal(hardwareSpec) require.NoError(t, err) - assert.Equal(t, tc.expected, string(hwSpecJSON)) + assert.JSONEq(t, tc.expected, string(hwSpecJSON)) }) } } diff --git a/cfn-resources/test/e2e/cluster/cluster_test.go b/cfn-resources/test/e2e/cluster/cluster_test.go index eaa42fd9b..00ff94a83 100644 --- a/cfn-resources/test/e2e/cluster/cluster_test.go +++ b/cfn-resources/test/e2e/cluster/cluster_test.go @@ -225,9 +225,10 @@ func checkReplicationSpecs(a *assert.Assertions, replicationSpecs []admin.Replic hwSpec := config.GetElectableSpecs() a.Equal(nodeCount, hwSpec.GetNodeCount()) } - if i == 0 { + switch i { + case 0: a.Equal(zone1, spec.GetZoneName()) - } else if i == 1 { + case 1: a.Equal(zone2, spec.GetZoneName()) } } diff --git a/cfn-resources/third-party-integration/cmd/resource/resource.go b/cfn-resources/third-party-integration/cmd/resource/resource.go index a983dba05..ba18a2406 100644 --- a/cfn-resources/third-party-integration/cmd/resource/resource.go +++ b/cfn-resources/third-party-integration/cmd/resource/resource.go @@ -326,11 +326,8 @@ func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) } func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegration) Model { - enabled := false // if "Enabled" is not set in the inputs we dont want to return "Enabled" in outputs - if currentModel.Enabled != nil { - enabled = true - } + enabled := currentModel.Enabled != nil /* The variables from the thirdparty integration are not returned back in reposnse because most of the variables are sensitive variables.