Skip to content

Commit 6f681bd

Browse files
committed
fixing a bunch of linting errors
1 parent d3c958a commit 6f681bd

File tree

10 files changed

+42
-38
lines changed

10 files changed

+42
-38
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o go-scaffold
2929

3030
FROM scratch AS production
3131

32-
COPY --from=builder /app/go-scaffold .
32+
COPY --from=builder /app/go-scaffold /
3333

3434
ENTRYPOINT [ "/go-scaffold" ]

internal/download/download_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"gotest.tools/v3/assert"
88
)
99

10-
func testGitUrl(url string, t *testing.T) {
10+
func testGitURL(url string, t *testing.T) {
1111
got := isGitRepo(url)
1212
if got != true {
1313
t.Errorf("%s was not detected as a valid git repository", url)
@@ -16,13 +16,13 @@ func testGitUrl(url string, t *testing.T) {
1616

1717
func TestDetectIsGitRepositoryShouldDetectValidRepositories(t *testing.T) {
1818
// support https
19-
testGitUrl("https://github.com/user/template.git", t)
19+
testGitURL("https://github.com/user/template.git", t)
2020

2121
// support SSH
22-
testGitUrl("[email protected]:user/template.git", t)
22+
testGitURL("[email protected]:user/template.git", t)
2323

2424
// support self hosted repos
25-
testGitUrl("[email protected]:user/template.git", t)
25+
testGitURL("[email protected]:user/template.git", t)
2626
}
2727

2828
func TestDetectIsOciArtifactUriShouldDetectValidUri(t *testing.T) {

internal/generate/filters.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func initFilters() {
1212
pongo2.RegisterFilter("slugify", filterSlugify)
1313
pongo2.RegisterFilter("yaml", filterYaml)
14-
pongo2.RegisterFilter("json", filterJson)
14+
pongo2.RegisterFilter("json", filterJSON)
1515
}
1616

1717
func filterSlugify(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
@@ -30,7 +30,7 @@ func filterYaml(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.E
3030
return pongo2.AsValue(string(yamlBytes)), nil
3131
}
3232

33-
func filterJson(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
33+
func filterJSON(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
3434
jsonBytes, err := json.MarshalIndent(in.Interface(), "", " ")
3535
if err != nil {
3636
return nil, &pongo2.Error{

internal/generate/generate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type TemplateMetadata struct {
12-
Uri string `json:"uri" yaml:"uri"`
12+
URI string `json:"uri" yaml:"uri"`
1313
Version string `json:"version" yaml:"version"`
1414
}
1515

internal/schema/schema.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func LoadSchema(schemaOrig interface{}) (*jsonschema.Schema, error) {
4949

5050
switch schemaRaw := schemaRaw.(type) {
5151
case []interface{}:
52-
if err := Merge(&schema, schemaRaw); err != nil {
52+
if err = Merge(&schema, schemaRaw); err != nil {
5353
return nil, err
5454
}
5555
case map[string]interface{}:

internal/template/docker.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ProgressDetail struct {
2727

2828
type DockerStatusMessage struct {
2929
Status string `json:"status"`
30-
Id string `json:"id"`
30+
ID string `json:"id"`
3131
ProgressDetail ProgressDetail `json:"progressDetail"`
3232
Progress string `json:"progress"`
3333
}
@@ -53,7 +53,7 @@ func (w *DockerImageWriter) Write(p []byte) (n int, err error) {
5353
return len(p), nil
5454
}
5555

56-
func (t *Template) executeActionStep(step Step, targetFs afero.Fs, outputFs afero.BasePathFs) error {
56+
func (t *Template) executeActionStep(step Step, _ afero.Fs, outputFs afero.BasePathFs) error {
5757
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
5858
defer cancel()
5959

@@ -101,13 +101,13 @@ func (t *Template) executeActionStep(step Step, targetFs afero.Fs, outputFs afer
101101
return err
102102
}
103103

104-
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
104+
if err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
105105
return err
106106
}
107107

108108
statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
109109
select {
110-
case err := <-errCh:
110+
case err = <-errCh:
111111
if err != nil {
112112
return err
113113
}

internal/template/step.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package template
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
76
"path/filepath"
87
"strings"
@@ -13,7 +12,7 @@ import (
1312
)
1413

1514
type Step struct {
16-
Id string `json:"id" yaml:"id"`
15+
ID string `json:"id" yaml:"id"`
1716
Description string `json:"description" yaml:"description"`
1817
Action string `json:"action" yaml:"action"`
1918
Target string `json:"target" yaml:"target"`
@@ -28,13 +27,13 @@ func mergeStepsFromConfigAndTemplateFilesystem(templateFs afero.Fs, config *Temp
2827

2928
if config.Steps != nil {
3029
for idx, step := range config.Steps {
31-
if step.Id == "" {
32-
step.Id = fmt.Sprintf("Step %d", idx)
30+
if step.ID == "" {
31+
step.ID = fmt.Sprintf("Step %d", idx)
3332
}
3433
step = *parseStep(&step)
3534

3635
if err := validateStep(step); err != nil {
37-
allErrors = append(allErrors, errors.New(fmt.Sprintf("step %+v is not valid: %s", step, err)))
36+
allErrors = append(allErrors, fmt.Errorf("step %+v is not valid: %s", step, err))
3837
}
3938

4039
validSteps = append(validSteps, step)
@@ -49,28 +48,28 @@ func mergeStepsFromConfigAndTemplateFilesystem(templateFs afero.Fs, config *Temp
4948
stepsFs := afero.NewBasePathFs(templateFs, "steps")
5049
files, err := afero.ReadDir(stepsFs, ".")
5150
if err != nil {
52-
allErrors = append(allErrors, errors.New(fmt.Sprintf("problem reading steps directory: %s", err)))
51+
allErrors = append(allErrors, fmt.Errorf("problem reading steps directory: %s", err))
5352
return validSteps, allErrors
5453
}
5554

5655
for _, file := range files {
5756
path := file.Name()
5857
step, err := loadStep(stepsFs, path)
5958
if err != nil {
60-
allErrors = append(allErrors, errors.New(fmt.Sprintf("step %s is not valid: %s", path, err)))
59+
allErrors = append(allErrors, fmt.Errorf("step %s is not valid: %s", path, err))
6160
continue
6261
}
6362

64-
if step.Id == "" {
63+
if step.ID == "" {
6564
base := filepath.Base(path)
6665
ext := filepath.Ext(path)
67-
step.Id = strings.TrimRight(base, ext)
66+
step.ID = strings.TrimRight(base, ext)
6867
}
6968
step = parseStep(step)
7069

7170
err = validateStep(*step)
7271
if err != nil {
73-
allErrors = append(allErrors, errors.New(fmt.Sprintf("step %s is not valid: %s", path, err)))
72+
allErrors = append(allErrors, fmt.Errorf("step %s is not valid: %s", path, err))
7473
continue
7574
}
7675

@@ -116,7 +115,7 @@ func loadStep(stepsFs afero.Fs, stepPath string) (*Step, error) {
116115
case ".json":
117116
fileType = JSON
118117
default:
119-
return nil, errors.New(fmt.Sprintf("unrecognized file extension %s", ext))
118+
return nil, fmt.Errorf("unrecognized file extension %s", ext)
120119
}
121120

122121
step, err := readStepFile(stepsFs, stepPath, fileType)
@@ -147,7 +146,7 @@ func parseStep(step *Step) *Step {
147146
func validateStep(step Step) error {
148147
if step.Action == "template" {
149148
if step.Source == "" {
150-
return errors.New(fmt.Sprintf("required field source not set on step ID %s", step.Id))
149+
return fmt.Errorf("required field source not set on step ID %s", step.ID)
151150
}
152151
}
153152

internal/template/template.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type MetaTemplate struct {
1616
}
1717

1818
type Template struct {
19-
Uri string `json:"uri" yaml:"uri"`
19+
URI string `json:"uri" yaml:"uri"`
2020
LocalPath string `json:"localPath" yaml:"localPath"`
2121
Version string `json:"version" yaml:"version"`
2222
Config *TemplateConfig `json:"config" yaml:"config"`
@@ -38,6 +38,9 @@ func NewTemplate(fs afero.Fs, uri string) (*MetaTemplate, error) {
3838
}
3939

4040
schema, err := schema.LoadSchema(template.Config.RawSchema)
41+
if err != nil {
42+
return nil, err
43+
}
4144

4245
return &MetaTemplate{
4346
Templates: deps,
@@ -63,13 +66,13 @@ func downloadTemplate(fs afero.Fs, uri string) (*Template, error) {
6366

6467
steps, stepErrors := mergeStepsFromConfigAndTemplateFilesystem(templateFs, config)
6568
if len(stepErrors) > 0 {
66-
err := errors.New("error loading steps")
69+
// err := errors.New("error loading steps")
6770
err = errors.Join(stepErrors...)
6871
return nil, err
6972
}
7073

7174
return &Template{
72-
Uri: uri,
75+
URI: uri,
7376
LocalPath: downloadInfo.LocalPath,
7477
Version: downloadInfo.Version,
7578
Config: config,
@@ -126,8 +129,8 @@ func isDependency(step Step, templateFs afero.Fs) bool {
126129

127130
func checkCircularDependency(templates []*Template, step Step) error {
128131
for _, t := range templates {
129-
if t.Uri == step.Source {
130-
return errors.New(fmt.Sprintf("using template at %s would cause a circular dependency", step.Source))
132+
if t.URI == step.Source {
133+
return fmt.Errorf("using template at %s would cause a circular dependency", step.Source)
131134
}
132135
}
133136

pkg/scaffold/scaffold.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99
"github.com/spf13/afero"
1010
)
1111

12-
type Template = t.MetaTemplate
13-
type GeneratedMetadata = g.GeneratedMetadata
12+
type (
13+
Template = t.MetaTemplate
14+
GeneratedMetadata = g.GeneratedMetadata
15+
)
1416

15-
func Download(templateUri string) (*Template, error) {
17+
func Download(templateURI string) (*Template, error) {
1618
fs := afero.NewOsFs()
17-
template, err := t.NewTemplate(fs, templateUri)
19+
template, err := t.NewTemplate(fs, templateURI)
1820
if err != nil {
1921
return nil, err
2022
}
@@ -39,13 +41,13 @@ func Generate(meta *Template, input *map[string]interface{}, outputPath string)
3941
for _, template := range meta.Templates {
4042
stepCreatedFiles, stepErrors := template.ExecuteSteps(input, fs, outputFs)
4143
if len(stepErrors) > 0 {
42-
err := errors.New("problem running steps")
43-
err = errors.Join(stepErrors...)
44+
// err := errors.New("problem running steps")
45+
err := errors.Join(stepErrors...)
4446
return nil, err
4547
}
4648
createdFiles = append(createdFiles, stepCreatedFiles...)
4749
templateMetadata = append(templateMetadata, g.TemplateMetadata{
48-
Uri: template.Uri,
50+
URI: template.URI,
4951
Version: template.Version,
5052
})
5153
}

testdata/template/steps/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
source: ./template
1+
source: ./template

0 commit comments

Comments
 (0)