Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/code-health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
200 changes: 88 additions & 112 deletions cfn-resources/.golangci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cfn-resources/cluster/cmd/resource/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes: encoded-compare: use assert.JSONEq (testifylint)

})
}
}
5 changes: 3 additions & 2 deletions cfn-resources/test/e2e/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ func checkReplicationSpecs(a *assert.Assertions, replicationSpecs []admin.Replic
hwSpec := config.GetElectableSpecs()
a.Equal(nodeCount, hwSpec.GetNodeCount())
}
if i == 0 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes: QF1003: could use tagged switch on i (staticcheck)

switch i {
case 0:
a.Equal(zone1, spec.GetZoneName())
} else if i == 1 {
case 1:
a.Equal(zone2, spec.GetZoneName())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,8 @@ func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration)
}

func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegration) Model {
enabled := false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes: QF1007: could merge conditional assignment into variable declaration (staticcheck)

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can never be false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be false if currentModel.Enabled == nil


/*
The variables from the thirdparty integration are not returned back in reposnse because most of the variables are sensitive variables.
Expand Down
Loading