Skip to content

Commit f831d81

Browse files
committed
chore: Fix lint failures
1 parent 04cb092 commit f831d81

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ issues:
118118
- ^vendor$
119119
- ^build$
120120
- ^pkg\/eks\/mocks$
121-
- ^pkg\/goformation$
121+
- ^pkg\/goformation*
122122

123123
# Which files to exclude: they will be analyzed, but issues from them won't be reported.
124124
# There is no need to include all autogenerated files,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ require (
7575
golang.org/x/crypto v0.33.0
7676
golang.org/x/oauth2 v0.25.0
7777
golang.org/x/sync v0.11.0
78+
golang.org/x/text v0.22.0
7879
golang.org/x/tools v0.30.0
7980
gopkg.in/yaml.v2 v2.4.0
8081
helm.sh/helm/v3 v3.17.0
@@ -405,7 +406,6 @@ require (
405406
golang.org/x/net v0.35.0 // indirect
406407
golang.org/x/sys v0.30.0 // indirect
407408
golang.org/x/term v0.29.0 // indirect
408-
golang.org/x/text v0.22.0 // indirect
409409
golang.org/x/time v0.8.0 // indirect
410410
google.golang.org/api v0.215.0 // indirect
411411
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect

pkg/goformation/generate/generate.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import (
55
"encoding/json"
66
"fmt"
77
"go/format"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"net/url"
1111
"os"
1212
"sort"
1313
"strings"
1414
"text/template"
15+
16+
"golang.org/x/text/cases"
17+
"golang.org/x/text/language"
1518
)
1619

1720
// ResourceGenerator takes AWS CloudFormation Resource Specification
@@ -138,14 +141,14 @@ func (rg *ResourceGenerator) downloadSpec(location string) ([]byte, error) {
138141
return nil, err
139142
}
140143

141-
data, err := ioutil.ReadAll(response.Body)
144+
data, err := io.ReadAll(response.Body)
142145
if err != nil {
143146
return nil, err
144147
}
145148

146149
return data, nil
147150
case "file":
148-
data, err := ioutil.ReadFile(strings.Replace(location, "file://", "", -1))
151+
data, err := os.ReadFile(strings.Replace(location, "file://", "", -1))
149152
if err != nil {
150153
return nil, err
151154
}
@@ -242,7 +245,7 @@ func (rg *ResourceGenerator) generateAllResourcesMap(resources []GeneratedResour
242245
}
243246

244247
// Write the file contents out
245-
if err := ioutil.WriteFile("cloudformation/all.go", formatted, 0644); err != nil {
248+
if err := os.WriteFile("cloudformation/all.go", formatted, 0644); err != nil {
246249
return fmt.Errorf("failed to write Go file for iterable map of all resources: %s", err)
247250
}
248251

@@ -344,7 +347,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
344347
// Check if the file has changed since the last time generate ran
345348
dir := "cloudformation/" + pname
346349
fn := dir + "/" + filename(name)
347-
current, err := ioutil.ReadFile(fn)
350+
current, err := os.ReadFile(fn)
348351

349352
if err != nil || bytes.Compare(formatted, current) != 0 {
350353

@@ -354,7 +357,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
354357
}
355358

356359
// Write the file contents out
357-
if err := ioutil.WriteFile(fn, formatted, 0644); err != nil {
360+
if err := os.WriteFile(fn, formatted, 0644); err != nil {
358361
return fmt.Errorf("failed to write resource file %s: %s", fn, err)
359362
}
360363
// Log the updated resource name to the results
@@ -403,20 +406,20 @@ func (rg *ResourceGenerator) generateJSONSchema(specname string, spec *CloudForm
403406
}
404407

405408
filename := fmt.Sprintf("schema/%s.schema.json", specname)
406-
if err := ioutil.WriteFile(filename, formatted, 0644); err != nil {
409+
if err := os.WriteFile(filename, formatted, 0644); err != nil {
407410
return fmt.Errorf("failed to write JSON Schema: %s", err)
408411
}
409412

410413
// Also create a Go importable version
411414
var gocode []byte
412415
gocode = append(gocode, []byte("package schema\n")...)
413416
gocode = append(gocode, []byte("\n")...)
414-
gocode = append(gocode, []byte("// "+strings.Title(specname)+"Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n")...)
415-
gocode = append(gocode, []byte("var "+strings.Title(specname)+"Schema = `")...)
417+
gocode = append(gocode, []byte("// "+cases.Title(language.Und, cases.NoLower).String(specname)+"Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n")...)
418+
gocode = append(gocode, []byte("var "+cases.Title(language.Und, cases.NoLower).String(specname)+"Schema = `")...)
416419
gocode = append(gocode, formatted...)
417420
gocode = append(gocode, []byte("`\n")...)
418421
gofilename := fmt.Sprintf("schema/%s.go", specname)
419-
if err := ioutil.WriteFile(gofilename, gocode, 0644); err != nil {
422+
if err := os.WriteFile(gofilename, gocode, 0644); err != nil {
420423
return fmt.Errorf("failed to write Go version of JSON Schema: %s", err)
421424
}
422425

@@ -430,7 +433,7 @@ func generatePolymorphicProperty(typename string, name string, property Property
430433

431434
// Open the polymorphic property template
432435
tmpl, err := template.New("polymorphic-property.template").Funcs(template.FuncMap{
433-
"convertToGoType": convertTypeToGo,
436+
"convertToGoType": convertTypeToGo,
434437
"convertToPureGoType": convertTypeToPureGo,
435438
}).ParseFiles("generate/templates/polymorphic-property.template")
436439

@@ -485,7 +488,7 @@ func generatePolymorphicProperty(typename string, name string, property Property
485488
}
486489

487490
// Write the file out
488-
if err := ioutil.WriteFile(dir+"/"+filename(name), formatted, 0644); err != nil {
491+
if err := os.WriteFile(dir+"/"+filename(name), formatted, 0644); err != nil {
489492
fmt.Printf("Error: Failed to write JSON Schema\n%s\n", err)
490493
os.Exit(1)
491494
}

pkg/goformation/generate/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (r Resource) Required() string {
7272
}
7373
}
7474

75-
// As Go doesn't provide ordering guarentees for maps, we should
75+
// As Go doesn't provide ordering guarantees for maps, we should
7676
// sort the required property names by alphabetical order so that
7777
// they don't shuffle on every generation, and cause annoying commit diffs
7878
sort.Strings(required)

pkg/goformation/goformation.go

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

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"os"
66
"strings"
77

88
"github.com/weaveworks/eksctl/pkg/goformation/cloudformation"
@@ -22,7 +22,7 @@ func Open(filename string) (*cloudformation.Template, error) {
2222
// Parsing can be tweaked via the specified options.
2323
func OpenWithOptions(filename string, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error) {
2424

25-
data, err := ioutil.ReadFile(filename)
25+
data, err := os.ReadFile(filename)
2626
if err != nil {
2727
return nil, err
2828
}

0 commit comments

Comments
 (0)