Skip to content

Commit 283f6ab

Browse files
fix(deps): update module github.com/golangci/golangci-lint to v2 (#1079)
* fix(deps): update module github.com/golangci/golangci-lint to v2 * Fix lint install --------- Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com> Co-authored-by: Toby Brain <[email protected]>
1 parent 1dccbe6 commit 283f6ab

File tree

13 files changed

+47
-522
lines changed

13 files changed

+47
-522
lines changed

.golangci.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# increase the default timeout for slow CI needs
2-
run:
3-
timeout: 300s
4-
concurrency: 0
1+
version: "2"
2+
linters:
3+
exclusions:
4+
generated: lax
5+
presets:
6+
- comments
7+
- common-false-positives
8+
- legacy
9+
- std-error-handling
10+
paths:
11+
- third_party$
12+
- builtin$
13+
- examples$
14+
formatters:
15+
exclusions:
16+
generated: lax
17+
paths:
18+
- third_party$
19+
- builtin$
20+
- examples$

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,18 @@ install: build ## Install built provider into the local terraform cache
245245

246246

247247
.PHONY: tools
248-
tools: $(GOBIN) ## Install useful tools for linting, docs generation and development
248+
tools: $(GOBIN) tools-golangci-lint ## Install useful tools for linting, docs generation and development
249249
@ cd tools && go install github.com/client9/misspell/cmd/misspell
250250
@ cd tools && go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
251-
@ cd tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint
252251
@ cd tools && go install github.com/goreleaser/goreleaser/v2
253252
@ cd tools && go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
254253
@ cd tools && go install go.uber.org/mock/mockgen
255254

255+
.PHONY: tools-golangci-lint
256+
tools-golangci-lint: ## Download golangci-lint locally if necessary.
257+
@[[ -f $(GOBIN)/golangci-lint ]] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.0.2
258+
259+
256260
.PHONY: misspell
257261
misspell:
258262
@ $(GOBIN)/misspell -error -source go ./internal/

internal/clients/api_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func buildEsClient(cfg config.Client) (*elasticsearch.Client, error) {
440440

441441
es, err := elasticsearch.NewClient(*cfg.Elasticsearch)
442442
if err != nil {
443-
return nil, fmt.Errorf("Unable to create Elasticsearch client: %w", err)
443+
return nil, fmt.Errorf("unable to create Elasticsearch client: %w", err)
444444
}
445445

446446
return es, nil
@@ -475,7 +475,7 @@ func buildKibanaClient(cfg config.Client) (*kibana.Client, error) {
475475
func buildKibanaOapiClient(cfg config.Client) (*kibana_oapi.Client, error) {
476476
client, err := kibana_oapi.NewClient(*cfg.KibanaOapi)
477477
if err != nil {
478-
return nil, fmt.Errorf("Unable to create KibanaOapi client: %w", err)
478+
return nil, fmt.Errorf("unable to create KibanaOapi client: %w", err)
479479
}
480480

481481
return client, nil
@@ -539,7 +539,7 @@ func buildSloClient(cfg config.Client, httpClient *http.Client) *slo.APIClient {
539539
func buildFleetClient(cfg config.Client) (*fleet.Client, error) {
540540
client, err := fleet.NewClient(*cfg.Fleet)
541541
if err != nil {
542-
return nil, fmt.Errorf("Unable to create Fleet client: %w", err)
542+
return nil, fmt.Errorf("unable to create Fleet client: %w", err)
543543
}
544544

545545
return client, nil

internal/clients/elasticsearch/enrich.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func getPolicyType(m map[string]enrichPolicyResponse) (string, error) {
3636
return policyType, nil
3737
}
3838
}
39-
return "", fmt.Errorf("Did not find expected policy type.")
39+
return "", fmt.Errorf("did not find expected policy type")
4040
}
4141

4242
func GetEnrichPolicy(ctx context.Context, apiClient *clients.ApiClient, policyName string) (*models.EnrichPolicy, diag.Diagnostics) {

internal/elasticsearch/cluster/snapshot_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ func flattenRepoSettings(r *models.SnapshotRepository, s map[string]*schema.Sche
431431
case schema.TypeInt, schema.TypeFloat:
432432
i, err := strconv.Atoi(v.(string))
433433
if err != nil {
434-
return nil, fmt.Errorf(`Failed to parse value = "%v" for setting = "%s"`, v, k)
434+
return nil, fmt.Errorf(`failed to parse value = "%v" for setting = "%s"`, v, k)
435435
}
436436
settings[k] = i
437437
case schema.TypeBool:
438438
b, err := strconv.ParseBool(v.(string))
439439
if err != nil {
440-
return nil, fmt.Errorf(`Failed to parse value = "%v" for setting = "%s"`, v, k)
440+
return nil, fmt.Errorf(`failed to parse value = "%v" for setting = "%s"`, v, k)
441441
}
442442
settings[k] = b
443443
default:

internal/elasticsearch/index/index/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func (model tfModel) getFieldValueByTagValue(tagName string, t reflect.Type) (at
444444
}
445445

446446
func convertSettingsKeyToTFFieldKey(settingKey string) string {
447-
return strings.Replace(settingKey, ".", "_", -1)
447+
return strings.ReplaceAll(settingKey, ".", "_")
448448
}
449449

450450
func (model aliasTfModel) toAPIModel() (models.IndexAlias, diag.Diagnostics) {

internal/elasticsearch/security/user_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestAccImportedUserDoesNotResetPassword(t *testing.T) {
134134
}
135135
body := fmt.Sprintf("{\"password\": \"%s\"}", userUpdatedPassword)
136136

137-
req := esClient.API.Security.ChangePassword.WithUsername(username)
137+
req := esClient.Security.ChangePassword.WithUsername(username)
138138
resp, err := esClient.Security.ChangePassword(strings.NewReader(body), req)
139139
if err != nil {
140140
return false, nil
@@ -175,7 +175,7 @@ func checkUserCanAuthenticate(username string, password string) func(*terraform.
175175
credentials := fmt.Sprintf("%s:%s", username, password)
176176
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(credentials)))
177177

178-
req := esClient.API.Security.Authenticate.WithHeader(map[string]string{"Authorization": authHeader})
178+
req := esClient.Security.Authenticate.WithHeader(map[string]string{"Authorization": authHeader})
179179
resp, err := esClient.Security.Authenticate(req)
180180
if err != nil {
181181
return err

internal/kibana/slo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func TestAccResourceSloErrors(t *testing.T) {
294294
}`
295295

296296
budgetingMethodFailConfig := getSLOConfig(sloVars{name: "budgetingmethodfail", indicatorType: "apm_latency_indicator"})
297-
budgetingMethodFailConfig = strings.Replace(budgetingMethodFailConfig, "budgeting_method = \"timeslices\"", "budgeting_method = \"supdawg\"", -1)
297+
budgetingMethodFailConfig = strings.ReplaceAll(budgetingMethodFailConfig, "budgeting_method = \"timeslices\"", "budgeting_method = \"supdawg\"")
298298

299299
resource.Test(t, resource.TestCase{
300300
PreCheck: func() { acctest.PreCheck(t) },

internal/kibana/synthetics/schema.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strconv"
8+
79
"github.com/disaster37/go-kibana-rest/v8/kbapi"
810
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
911
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
@@ -25,7 +27,6 @@ import (
2527
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
2628
"github.com/hashicorp/terraform-plugin-framework/types"
2729
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
28-
"strconv"
2930
)
3031

3132
const (
@@ -857,7 +858,7 @@ func (v *tfModelV0) toMonitorFields(ctx context.Context) (kbapi.MonitorFields, d
857858

858859
func toTFAlertConfig(ctx context.Context, v basetypes.ObjectValue) *kbapi.MonitorAlertConfig {
859860
var alert *kbapi.MonitorAlertConfig
860-
if !(v.IsNull() || v.IsUnknown()) {
861+
if !v.IsNull() && !v.IsUnknown() {
861862
tfAlert := tfAlertConfigV0{}
862863
tfsdk.ValueAs(ctx, v, &tfAlert)
863864
alert = tfAlert.toTfAlertConfigV0()
@@ -899,7 +900,7 @@ func tfInt64ToString(v types.Int64) string {
899900
func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p string) (*kbapi.SSLConfig, diag.Diagnostics) {
900901

901902
var ssl *kbapi.SSLConfig
902-
if !(v.SslSupportedProtocols.IsNull() || v.SslSupportedProtocols.IsUnknown()) {
903+
if !v.SslSupportedProtocols.IsNull() && !v.SslSupportedProtocols.IsUnknown() {
903904
sslSupportedProtocols := utils.ListTypeToSlice_String(ctx, v.SslSupportedProtocols, path.Root(p).AtName("ssl_supported_protocols"), &dg)
904905
if dg.HasError() {
905906
return nil, dg
@@ -908,7 +909,7 @@ func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p stri
908909
ssl.SupportedProtocols = sslSupportedProtocols
909910
}
910911

911-
if !(v.SslVerificationMode.IsNull() || v.SslVerificationMode.IsUnknown()) {
912+
if !v.SslVerificationMode.IsNull() && !v.SslVerificationMode.IsUnknown() {
912913
if ssl == nil {
913914
ssl = &kbapi.SSLConfig{}
914915
}
@@ -923,21 +924,21 @@ func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p stri
923924
ssl.CertificateAuthorities = certAuths
924925
}
925926

926-
if !(v.SslCertificate.IsUnknown() || v.SslCertificate.IsNull()) {
927+
if !v.SslCertificate.IsUnknown() && !v.SslCertificate.IsNull() {
927928
if ssl == nil {
928929
ssl = &kbapi.SSLConfig{}
929930
}
930931
ssl.Certificate = v.SslCertificate.ValueString()
931932
}
932933

933-
if !(v.SslKey.IsUnknown() || v.SslKey.IsNull()) {
934+
if !v.SslKey.IsUnknown() && !v.SslKey.IsNull() {
934935
if ssl == nil {
935936
ssl = &kbapi.SSLConfig{}
936937
}
937938
ssl.Key = v.SslKey.ValueString()
938939
}
939940

940-
if !(v.SslKeyPassphrase.IsUnknown() || v.SslKeyPassphrase.IsNull()) {
941+
if !v.SslKeyPassphrase.IsUnknown() && !v.SslKeyPassphrase.IsNull() {
941942
if ssl == nil {
942943
ssl = &kbapi.SSLConfig{}
943944
}

internal/utils/utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
providerSchema "github.com/elastic/terraform-provider-elasticstack/internal/schema"
13-
"github.com/hashicorp/terraform-plugin-framework/diag"
1413
fwdiag "github.com/hashicorp/terraform-plugin-framework/diag"
1514
"github.com/hashicorp/terraform-plugin-framework/path"
1615
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -146,7 +145,7 @@ func ExpandIndividuallyDefinedSettings(ctx context.Context, d *schema.ResourceDa
146145
}
147146

148147
func ConvertSettingsKeyToTFFieldKey(settingKey string) string {
149-
return strings.Replace(settingKey, ".", "_", -1)
148+
return strings.ReplaceAll(settingKey, ".", "_")
150149
}
151150

152151
func Pointer[T any](value T) *T {
@@ -232,7 +231,7 @@ func ConvertToAttrDiags(diags fwdiag.Diagnostics, path path.Path) fwdiag.Diagnos
232231
for _, d := range diags {
233232
if d.Severity() == fwdiag.SeverityError {
234233
nd.AddAttributeError(path, d.Summary(), d.Detail())
235-
} else if d.Severity() == diag.SeverityWarning {
234+
} else if d.Severity() == fwdiag.SeverityWarning {
236235
nd.AddAttributeWarning(path, d.Summary(), d.Detail())
237236
} else {
238237
nd.Append(d)

0 commit comments

Comments
 (0)