Skip to content

Commit 9459acf

Browse files
authored
chore: add support for staticcheck (#2181)
1 parent 9fa83a1 commit 9459acf

File tree

15 files changed

+105
-42
lines changed

15 files changed

+105
-42
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ linters:
2424
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
2525
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
2626
- mirror # reports wrong mirror patterns of bytes/strings usage [fast: false, auto-fix: false]
27+
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
2728
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
2829
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
2930
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]

api/domain/v2beta1/domain_utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package domain
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/scaleway/scaleway-sdk-go/internal/async"
@@ -66,7 +65,7 @@ func (s *API) WaitForDNSZone(
6665
}
6766

6867
if len(DNSZones.DNSZones) == 0 {
69-
return nil, true, fmt.Errorf(ErrCodeNoSuchDNSZone)
68+
return nil, true, errors.New(ErrCodeNoSuchDNSZone)
7069
}
7170

7271
Dns := DNSZones.DNSZones[0]
@@ -120,7 +119,7 @@ func (s *API) WaitForDNSRecordExist(
120119
}
121120

122121
if DNSRecords.TotalCount == 0 {
123-
return nil, false, fmt.Errorf(ErrCodeNoSuchDNSRecord)
122+
return nil, false, errors.New(ErrCodeNoSuchDNSRecord)
124123
}
125124

126125
record := DNSRecords.Records[0]

api/instance/v1/instance_metadata_sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package instance
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"math/rand"
88
"net"
99
"net/http"
@@ -226,7 +226,7 @@ func (meta *MetadataAPI) GetUserData(key string) ([]byte, error) {
226226
}
227227
defer resp.Body.Close()
228228

229-
body, err := ioutil.ReadAll(resp.Body)
229+
body, err := io.ReadAll(resp.Body)
230230
if err != nil {
231231
return make([]byte, 0), errors.Wrap(err, "error reading userdata body")
232232
}

api/instance/v1/server_utils_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package instance
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"strings"
87
"testing"
98

@@ -69,7 +68,7 @@ func TestAPI_ServerUserData(t *testing.T) {
6968
})
7069
testhelpers.AssertNoError(t, err)
7170

72-
resUserData, err := ioutil.ReadAll(data)
71+
resUserData, err := io.ReadAll(data)
7372
testhelpers.AssertNoError(t, err)
7473
testhelpers.Equals(t, contentStr, string(resUserData))
7574
}
@@ -137,7 +136,7 @@ func TestAPI_AllServerUserData(t *testing.T) {
137136
currentReader, exists := allData.UserData[expectedKey]
138137
testhelpers.Assert(t, exists, "%s key not found in result", expectedKey)
139138

140-
currentValue, err := ioutil.ReadAll(currentReader)
139+
currentValue, err := io.ReadAll(currentReader)
141140
testhelpers.AssertNoError(t, err)
142141

143142
testhelpers.Equals(t, expectedValue, string(currentValue))

api/k8s/v1/kubeconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package k8s
22

33
import (
4-
"io/ioutil"
4+
"io"
55

66
"github.com/scaleway/scaleway-sdk-go/internal/errors"
77
"github.com/scaleway/scaleway-sdk-go/scw"
@@ -101,7 +101,7 @@ func (s *API) GetClusterKubeConfig(req *GetClusterKubeConfigRequest, opts ...scw
101101
return nil, errors.Wrap(err, "error getting cluster kubeconfig")
102102
}
103103

104-
kubeconfigContent, err := ioutil.ReadAll(kubeconfigFile.Content)
104+
kubeconfigContent, err := io.ReadAll(kubeconfigFile.Content)
105105
if err != nil {
106106
return nil, errors.Wrap(err, "error reading kubeconfig content")
107107
}

example_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Example_apiClient() {
2020

2121
// Create SDK objects for specific Scaleway Products
2222
instanceAPI := instance.NewAPI(client)
23-
lbAPI := lb.NewAPI(client)
23+
lbAPI := lb.NewZonedAPI(client)
2424

2525
// Start using the SDKs
2626
_, _ = instanceAPI, lbAPI
@@ -50,7 +50,7 @@ func Example_apiClientWithConfig() {
5050

5151
// Create SDK objects for specific Scaleway Products
5252
instanceAPI := instance.NewAPI(client)
53-
lbAPI := lb.NewAPI(client)
53+
lbAPI := lb.NewZonedAPI(client)
5454

5555
// Start using the SDKs
5656
_, _ = instanceAPI, lbAPI
@@ -191,14 +191,12 @@ func Example_createLoadBalancer() {
191191
}
192192

193193
// Create SDK objects for Scaleway LoadConfig Balancer product
194-
lbAPI := lb.NewAPI(client)
194+
lbAPI := lb.NewZonedAPI(client)
195195

196196
// Call the CreateLb method on the LB SDK to create a new load balancer.
197-
newLB, err := lbAPI.CreateLB(&lb.CreateLBRequest{
198-
Name: "My new load balancer",
199-
Description: "This is a example of a load balancer",
200-
OrganizationID: scw.StringPtr("000a115d-2852-4b0a-9ce8-47f1134ba95a"),
201-
Region: scw.RegionFrPar,
197+
newLB, err := lbAPI.CreateLB(&lb.ZonedAPICreateLBRequest{
198+
Name: "My new load balancer",
199+
Description: "This is a example of a load balancer",
202200
})
203201
if err != nil {
204202
// handle error

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/scaleway/scaleway-sdk-go
33
go 1.17
44

55
require (
6-
github.com/dnaeon/go-vcr v1.2.0 // indirect
7-
gopkg.in/yaml.v2 v2.4.0 // indirect
6+
github.com/dnaeon/go-vcr v1.2.0
7+
golang.org/x/text v0.17.0
8+
gopkg.in/yaml.v2 v2.4.0
89
)

go.sum

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,70 @@
11
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
22
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
3+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
34
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
5+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
6+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
8+
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
9+
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
10+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
11+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
12+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
13+
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
14+
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
15+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
16+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
17+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
18+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
19+
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
20+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
21+
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
22+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
23+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
24+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
25+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
26+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
28+
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
29+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
30+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
31+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
32+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
33+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
36+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
39+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
40+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
41+
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
42+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
43+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
44+
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
45+
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
46+
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
47+
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
48+
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
49+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
51+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
52+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
53+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
54+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
55+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
56+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
57+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
58+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
59+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
60+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
61+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
62+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
63+
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
64+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
65+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
66+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
467
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5-
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
668
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
769
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
870
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

logger/default_logger.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package logger
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"log"
87
"os"
98
"strconv"
@@ -79,10 +78,10 @@ func isEnabled(envKey string) bool {
7978
// newLogger creates a logger to be used as default logger.
8079
// All logs are written to w.
8180
func newLogger(w io.Writer, level LogLevel) *loggerT {
82-
errorW := ioutil.Discard
83-
warningW := ioutil.Discard
84-
infoW := ioutil.Discard
85-
debugW := ioutil.Discard
81+
errorW := io.Discard
82+
warningW := io.Discard
83+
infoW := io.Discard
84+
debugW := io.Discard
8685
if isEnabled(DebugEnv) {
8786
level = LogLevelDebug
8887
}

scw/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scw
33
import (
44
"bytes"
55
goerrors "errors"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"strings"
@@ -217,7 +216,7 @@ func LoadConfigFromPath(path string) (*Config, error) {
217216
return nil, err
218217
}
219218

220-
file, err := ioutil.ReadFile(path)
219+
file, err := os.ReadFile(path)
221220
if err != nil {
222221
return nil, errors.Wrap(err, "cannot read config file")
223222
}
@@ -304,7 +303,7 @@ func (c *Config) SaveTo(path string) error {
304303
}
305304

306305
// STEP 3: write new config file
307-
err = ioutil.WriteFile(path, []byte(file), defaultConfigPermission)
306+
err = os.WriteFile(path, []byte(file), defaultConfigPermission)
308307
if err != nil {
309308
return err
310309
}

scw/config_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scw
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"strings"
@@ -245,7 +244,7 @@ func TestSaveConfig(t *testing.T) {
245244
for fileName := range test.expectedFiles {
246245
expectedContent, err := test.config.HumanConfig()
247246
testhelpers.AssertNoError(t, err)
248-
content, err := ioutil.ReadFile(filepath.Join(dir, fileName))
247+
content, err := os.ReadFile(filepath.Join(dir, fileName))
249248
testhelpers.AssertNoError(t, err)
250249
testhelpers.Equals(t, expectedContent, string(content))
251250
}
@@ -509,7 +508,7 @@ func TestMergeProfiles(t *testing.T) {
509508
}
510509

511510
func initEnv(t *testing.T) string {
512-
dir, err := ioutil.TempDir("", "home")
511+
dir, err := os.MkdirTemp("", "home")
513512
if err != nil {
514513
t.Fatal(err)
515514
}
@@ -532,7 +531,7 @@ func setEnv(t *testing.T, env, files map[string]string, homeDir string) {
532531
for path, content := range files {
533532
targetPath := filepath.Join(homeDir, path)
534533
testhelpers.AssertNoError(t, os.MkdirAll(filepath.Dir(targetPath), 0o700))
535-
testhelpers.AssertNoError(t, ioutil.WriteFile(targetPath, []byte(content), defaultConfigPermission))
534+
testhelpers.AssertNoError(t, os.WriteFile(targetPath, []byte(content), defaultConfigPermission))
536535
}
537536
}
538537

scw/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scw
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"sort"
99
"strings"
@@ -97,7 +97,7 @@ func hasResponseError(res *http.Response) error {
9797
return newErr
9898
}
9999

100-
body, err := ioutil.ReadAll(res.Body)
100+
body, err := io.ReadAll(res.Body)
101101
if err != nil {
102102
return errors.Wrap(err, "cannot read error response body")
103103
}

scw/errors_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scw
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"strings"
99
"testing"
@@ -39,7 +39,7 @@ func TestNonStandardError(t *testing.T) {
3939
res := &http.Response{
4040
Status: c.resStatus,
4141
StatusCode: c.resStatusCode,
42-
Body: ioutil.NopCloser(strings.NewReader(c.resBody)),
42+
Body: io.NopCloser(strings.NewReader(c.resBody)),
4343
Header: http.Header{
4444
"Content-Type": []string{c.contentType},
4545
},
@@ -196,7 +196,7 @@ func TestHasResponseErrorWithValidError(t *testing.T) {
196196
Header: map[string][]string{
197197
"Content-Type": {"application/json"},
198198
},
199-
Body: ioutil.NopCloser(bytes.NewReader(bodyBytes)),
199+
Body: io.NopCloser(bytes.NewReader(bodyBytes)),
200200
}
201201

202202
// Test hasResponseError()

scw/load_config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scw
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"strings"
@@ -149,7 +148,7 @@ func TestLoad(t *testing.T) {
149148
// test expected files
150149
for path, expectedContent := range test.expectedFiles {
151150
targetPath := filepath.Join(dir, path)
152-
content, err := ioutil.ReadFile(targetPath)
151+
content, err := os.ReadFile(targetPath)
153152
testhelpers.AssertNoError(t, err)
154153
testhelpers.Equals(t, expectedContent, string(content))
155154
testhelpers.AssertNoError(t, os.RemoveAll(targetPath)) // delete at the end

strcase/bash_arg.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package strcase
22

3-
import "strings"
3+
import (
4+
"strings"
5+
6+
"golang.org/x/text/cases"
7+
"golang.org/x/text/language"
8+
)
49

510
var customBashNames = map[string]string{
611
"aclid": "acl-id",
@@ -15,9 +20,11 @@ func ToBashArg(s string) string {
1520
if customBashName, exists := customBashNames[strings.ToLower(s)]; exists {
1621
return customBashName
1722
}
23+
24+
caser := cases.Title(language.English)
1825
for _, initialism := range customInitialisms {
1926
// catch this kind of pattern: ExampleIDs ==> ExampleIds ==> example-ids
20-
s = strings.ReplaceAll(s, initialism[0], strings.Title(strings.ToLower(initialism[0])))
27+
s = strings.ReplaceAll(s, initialism[0], caser.String(strings.ToLower(initialism[0])))
2128
}
2229
return toKebab(s)
2330
}

0 commit comments

Comments
 (0)