Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
go-version-file: '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.64.7 # Also update GOLANGCI_VERSION variable in GNUmakefile when updating this version
version: v2.0.2 # Also update GOLANGCI_VERSION variable in GNUmakefile when updating this version
- name: actionlint
run: |
make tools
Expand Down
223 changes: 109 additions & 114 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,134 +1,129 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
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
- unconvert
- unused
- whitespace
- thelper
- testifylint
- exhaustive
- makezero
- noctx
- testpackage
- thelper
- unconvert
- unused
- usetesting
- whitespace
# Too many unusued parameters, skipping this check for now
#- name: unused-parameter

# don't enable:
# - tenv # The linter 'tenv' is deprecated (since v1.64.0) due to: Duplicate feature another linter. Replaced by usetesting.
# - 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 .*
exclude-rules:
- linters:
- staticcheck
text: "SA1019:" # d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK
- linters:
- gocritic
text: "^hugeParam: req is heavy"
- path: "schema\\.go" # exclude rules for schema files as it's auto-genereated from OpenAPI spec
text: "fieldalignment|hugeParam|var-naming|ST1003|S1007|exceeds the maximum|too long|regexpSimplify|nolint"
run:
timeout: 10m
tests: true
build-tags:
- integration
modules-download-mode: readonly
settings:
funlen:
lines: 360
statements: 120
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable-all: true
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
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:
- linters:
- staticcheck
text: "SA1019:" # d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK
- linters:
- gocritic
text: "^hugeParam: req is heavy"
- path: schema\.go # exclude rules for schema files as it's auto-genereated from OpenAPI spec
text: fieldalignment|hugeParam|var-naming|ST1003|S1007|exceeds the maximum|too long|regexpSimplify|nolint
- path: (.+)\.go$
text: declaration of ".*" shadows declaration at line .*
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GITTAG=$(shell git describe --always --tags)
VERSION=$(GITTAG:v%=%)
LINKER_FLAGS=-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=${VERSION}'

GOLANGCI_VERSION=v1.64.7 # 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

export PATH := $(shell go env GOPATH)/bin:$(PATH)
export SHELL := env PATH=$(PATH) /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion internal/common/conversion/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestToAnySlicePointer(t *testing.T) {
assert.Nil(t, value)
} else {
assert.NotNil(t, ret)
assert.Equal(t, len(*value), len(*ret))
assert.Len(t, *value, len(*ret))
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: len: use assert.Len (testifylint)

for i := range *value {
assert.Equal(t, (*value)[i], (*ret)[i])
}
Expand Down
2 changes: 1 addition & 1 deletion internal/common/conversion/type_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestSafeValue(t *testing.T) {
var intPointer *int
assert.Equal(t, 0, conversion.SafeValue(intPointer))
var stringPointer *string
assert.Equal(t, "", conversion.SafeValue(stringPointer))
assert.Empty(t, conversion.SafeValue(stringPointer))
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: empty: use assert.NotEmpty (testifylint)

}

func TestNilForUnknownOrEmpty(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func validateDeliveryType(dt []any) error {
oplogInc, oplogIncOk := v["oplog_inc"]
isOpIncSet := oplogIncOk && oplogInc != nil && (oplogInc.(int) > 0)

if !isPITSet && !(isOpTSSet && isOpIncSet) {
if !isPITSet && (!isOpTSSet || !isOpIncSet) {
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: QF1001: could apply De Morgan's law (staticcheck)

return fmt.Errorf("%q point_in_time_utc_seconds or oplog_ts and oplog_inc must be set", key)
}
if isPITSet && (isOpTSSet || isOpIncSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
projectID, projectIDOk := d.GetOk("project_id")
clusterName, clusterNameOk := d.GetOk("cluster_name")

if !(projectIDOk && clusterNameOk) {
if !projectIDOk || !clusterNameOk {
return diag.Errorf("project_id and cluster_name must be configured")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/searchindex/data_source_search_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour
clusterName, clusterNameOK := d.GetOk("cluster_name")
indexID, indexIDOk := d.GetOk("index_id")

if !(projectIDOk && clusterNameOK && indexIDOk) {
if !projectIDOk || !clusterNameOK || !indexIDOk {
return diag.Errorf("project_id, cluster_name and index_id must be configured")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func dataSourceMongoDBAtlasSearchIndexesRead(ctx context.Context, d *schema.Reso
databaseName, databaseNameOK := d.GetOk("database")
collectionName, collectionNameOK := d.GetOk("collection_name")

if !(projectIDOK && clusterNameOk && databaseNameOK && collectionNameOK) {
if !projectIDOK || !clusterNameOk || !databaseNameOK || !collectionNameOK {
return diag.Errorf("project_id, cluster_name, database and collection_name must be configured")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
projectID, projectIDOk := d.GetOk("project_id")
instanceName, instanceNameOk := d.GetOk("name")

if !(projectIDOk && instanceNameOk) {
if !projectIDOk || !instanceNameOk {
return diag.Errorf("project_id and name must be configured")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/streamprocessor/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ func configConnection(t *testing.T, projectID string, config connectionConfig) (
case "Cluster":
var connectionName, resourceName string
clusterName := config.clusterName
assert.NotEqual(t, "", clusterName)
assert.NotEmpty(t, clusterName)
if pipelineStepIsSource {
connectionName = "ClusterConnectionSrc"
resourceName = "cluster_src"
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/unit/http_mocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func enableReplayForTestCase(t *testing.T, config *MockHTTPDataConfig, testCase
require.NoError(t, config.RunBeforeEach())
}
}
require.Equal(t, len(testCase.Steps), len(data.Steps), "Number of steps in test case and mock data should match")
require.Len(t, testCase.Steps, len(data.Steps), "Number of steps in test case and mock data should match")
checkFunc := mockRoundTripper.CheckStepRequests
for i := range testCase.Steps {
step := &testCase.Steps[i]
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/unit/http_mocker_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type MockHTTPData struct {

func (m *MockHTTPData) useTFConfigs(t *testing.T, tfConfigs []string) {
t.Helper()
require.Equal(t, len(tfConfigs), len(m.Steps), "Number of steps in test case and mock data should match")
require.Len(t, tfConfigs, len(m.Steps), "Number of steps in test case and mock data should match")
for i := range tfConfigs {
tfConfig := tfConfigs[i]
configVars := ExtractConfigVariables(t, tfConfig)
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/unit/http_mocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestExtractVersionRequestResponse(t *testing.T) {

func TestExtractVersionRequestResponseNotFound(t *testing.T) {
version := unit.ExtractVersionRequestResponse("application/json;", "application/vnd.atlas.2023-01+json;charset=utf-8")
require.Equal(t, "", version)
require.Empty(t, version)
}

func asURL(t *testing.T, reqPath string) *url.URL {
Expand Down