Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit f1ef6b3

Browse files
committed
lint corrections
1 parent fc62b37 commit f1ef6b3

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

cmd/root.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func initConfig() error {
132132
}
133133

134134
func bindParams(cmd *cobra.Command) error {
135+
var err error
135136
cmd.Flags().VisitAll(func(f *pflag.Flag) {
136137
configName := strings.ReplaceAll(f.Name, "-", "")
137138

@@ -151,12 +152,15 @@ func bindParams(cmd *cobra.Command) error {
151152
for _, val := range v {
152153
values = append(values, fmt.Sprintf("%v", val))
153154
}
154-
cmd.Flags().Set(f.Name, strings.Join(values, ","))
155+
err = cmd.Flags().Set(f.Name, strings.Join(values, ","))
155156
default:
156-
cmd.Flags().Set(f.Name, fmt.Sprintf("%v", v))
157+
err = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", v))
158+
}
159+
if err != nil {
160+
return
157161
}
158162
}
159163
})
160164

161-
return nil
165+
return err
162166
}

internal/flow/export.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ func NewFromPath(pathToJson string) (*DaVinciExport, error) {
2525
}
2626

2727
// Get the string from file
28-
dvExport.readJSONFile()
28+
err := dvExport.readJSONFile()
29+
if err != nil {
30+
return nil, err
31+
}
2932

3033
return &dvExport, nil
3134
}

internal/generate/generate.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (d *DaVinciGenerator) buildDataSingleFlow(flow davinci.Flow, parsedIntf map
313313
DependsOnVarRefs: dependsOnVarRefs,
314314
Name: d.sanitiseStringFieldPtr(&flow.Name),
315315
Description: d.sanitiseStringFieldPtr(flow.Description),
316-
FlowJSONPath: fmt.Sprintf("%s", pathVar),
316+
FlowJSONPath: pathVar,
317317
ConnectionLinks: flowConnectionLinks,
318318
SubflowLinks: subflowLinks,
319319
})
@@ -391,7 +391,7 @@ func (d *DaVinciGenerator) writeVariables(version string, overwrite bool) error
391391
return fmt.Errorf("failed to parse variable HCL template. err: %s", err.Error())
392392
}
393393

394-
fileName := d.outputPath + fmt.Sprintf("/davinci_variables.tf")
394+
fileName := fmt.Sprintf("%s/davinci_variables.tf", d.outputPath)
395395

396396
// Check if the file exists
397397
if _, err := os.Stat(fileName); err == nil {
@@ -403,10 +403,10 @@ func (d *DaVinciGenerator) writeVariables(version string, overwrite bool) error
403403
}
404404

405405
outputFile, err := os.Create(fileName)
406-
defer outputFile.Close()
407406
if err != nil {
408407
return err
409408
}
409+
defer outputFile.Close()
410410

411411
for _, variableData := range d.variablesData {
412412
err = hclTemplate.Execute(outputFile, variableData)
@@ -433,7 +433,7 @@ func (d *DaVinciGenerator) writeConnections(version string, overwrite bool) erro
433433
return fmt.Errorf("failed to parse connection HCL template. err: %s", err.Error())
434434
}
435435

436-
fileName := d.outputPath + fmt.Sprintf("/davinci_connectors.tf")
436+
fileName := fmt.Sprintf("%s/davinci_connectors.tf", d.outputPath)
437437

438438
// Check if the file exists
439439
if _, err := os.Stat(fileName); err == nil {
@@ -445,10 +445,10 @@ func (d *DaVinciGenerator) writeConnections(version string, overwrite bool) erro
445445
}
446446

447447
outputFile, err := os.Create(fileName)
448-
defer outputFile.Close()
449448
if err != nil {
450449
return err
451450
}
451+
defer outputFile.Close()
452452

453453
for _, connectionData := range d.connectionsData {
454454
err = hclTemplate.Execute(outputFile, connectionData)
@@ -474,7 +474,7 @@ func (d *DaVinciGenerator) writeFlows(version string, overwrite bool) error {
474474
return fmt.Errorf("failed to parse flow HCL template. err: %s", err.Error())
475475
}
476476

477-
fileName := d.outputPath + fmt.Sprintf("/davinci_flows.tf")
477+
fileName := fmt.Sprintf("%s/davinci_flows.tf", d.outputPath)
478478

479479
// Check if the file exists
480480
if _, err := os.Stat(fileName); err == nil {
@@ -486,10 +486,10 @@ func (d *DaVinciGenerator) writeFlows(version string, overwrite bool) error {
486486
}
487487

488488
outputFile, err := os.Create(fileName)
489-
defer outputFile.Close()
490489
if err != nil {
491490
return err
492491
}
492+
defer outputFile.Close()
493493

494494
for _, flowData := range d.flowsData {
495495
err = hclTemplate.Execute(outputFile, flowData)
@@ -503,7 +503,7 @@ func (d *DaVinciGenerator) writeFlows(version string, overwrite bool) error {
503503

504504
func (d *DaVinciGenerator) writeAssets() error {
505505

506-
outputDir := d.outputPath + fmt.Sprintf("/assets/flows/")
506+
outputDir := fmt.Sprintf("%s/assets/flows/", d.outputPath)
507507

508508
err := os.MkdirAll(outputDir, os.ModePerm)
509509
if err != nil {
@@ -523,6 +523,9 @@ func (d *DaVinciGenerator) writeAssets() error {
523523
func (d *DaVinciGenerator) writeAsset(flowAsset flowAssetData) error {
524524

525525
fileData, err := json.MarshalIndent(flowAsset.flowMap, "", " ")
526+
if err != nil {
527+
return fmt.Errorf("Cannot marshal asset data: %s", err)
528+
}
526529

527530
err = os.WriteFile(fmt.Sprintf("%s/%s", d.outputPath, flowAsset.path), fileData, 0644)
528531
if err != nil {

internal/validate/validate.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,42 +182,42 @@ func (d *DaVinciValidator) OutputValidationResponse(vErr error) (ok, warning boo
182182
case errors.Is(vErr, ErrSubflowsPresent):
183183

184184
outputOpts = output.Opts{
185-
Message: fmt.Sprintf("Subflows are present in the export file. Subflows must be managed as their own independent davinci_flow resources. Please re-export the DaVinci flow without subflows."),
185+
Message: "Subflows are present in the export file. Subflows must be managed as their own independent davinci_flow resources. Please re-export the DaVinci flow without subflows.",
186186
Result: output.ENUM_RESULT_FAILURE,
187187
}
188188

189189
case errors.Is(vErr, davinci.ErrInvalidJson):
190190

191191
outputOpts = output.Opts{
192-
Message: fmt.Sprintf("The DaVinci Flow Export JSON is not valid JSON. Please re-export the DaVinci flow."),
192+
Message: "The DaVinci Flow Export JSON is not valid JSON. Please re-export the DaVinci flow.",
193193
Result: output.ENUM_RESULT_FAILURE,
194194
}
195195

196196
case errors.Is(vErr, davinci.ErrEmptyFlow):
197197

198198
outputOpts = output.Opts{
199-
Message: fmt.Sprintf("The DaVinci Flow Export JSON is empty. Please re-export the DaVinci flow."),
199+
Message: "The DaVinci Flow Export JSON is empty. Please re-export the DaVinci flow.",
200200
Result: output.ENUM_RESULT_FAILURE,
201201
}
202202

203203
case errors.Is(vErr, davinci.ErrNoFlowDefinition):
204204

205205
outputOpts = output.Opts{
206-
Message: fmt.Sprintf("No flow definition found in the DaVinci Flow Export JSON. Expecting exactly one flow definition. Please re-export the DaVinci flow."),
206+
Message: "No flow definition found in the DaVinci Flow Export JSON. Expecting exactly one flow definition. Please re-export the DaVinci flow.",
207207
Result: output.ENUM_RESULT_FAILURE,
208208
}
209209

210210
case errors.Is(vErr, davinci.ErrMissingSaveVariableValues):
211211

212212
outputOpts = output.Opts{
213-
Message: fmt.Sprintf("Save flow variable nodes are present but are missing variable values in the DaVinci Flow Export JSON. Please re-export the DaVinci flow ensuring that variable values are included."),
213+
Message: "Save flow variable nodes are present but are missing variable values in the DaVinci Flow Export JSON. Please re-export the DaVinci flow ensuring that variable values are included.",
214214
Result: output.ENUM_RESULT_FAILURE,
215215
}
216216

217217
case errors.As(vErr, &equatesEmptyError):
218218

219219
outputOpts = output.Opts{
220-
Message: fmt.Sprintf("The JSON does not appear to be a valid DaVinci export file. Please re-export the DaVinci flow."),
220+
Message: "The JSON does not appear to be a valid DaVinci export file. Please re-export the DaVinci flow.",
221221
Result: output.ENUM_RESULT_FAILURE,
222222
Fields: map[string]interface{}{
223223
"Computed Difference (empty is failure)": equatesEmptyError.Diff,
@@ -227,7 +227,7 @@ func (d *DaVinciValidator) OutputValidationResponse(vErr error) (ok, warning boo
227227
case errors.As(vErr, &missingRequiredFlowFieldsError):
228228

229229
outputOpts = output.Opts{
230-
Message: fmt.Sprintf("The DaVinci Flow Export JSON has been evaluated to be missing required fields. Please re-export the DaVinci flow."),
230+
Message: "The DaVinci Flow Export JSON has been evaluated to be missing required fields. Please re-export the DaVinci flow.",
231231
Result: output.ENUM_RESULT_FAILURE,
232232
Fields: map[string]interface{}{
233233
"Computed Difference": missingRequiredFlowFieldsError.Diff,
@@ -237,7 +237,7 @@ func (d *DaVinciValidator) OutputValidationResponse(vErr error) (ok, warning boo
237237
case errors.As(vErr, &unknownAdditionalFieldsError):
238238

239239
outputOpts = output.Opts{
240-
Message: fmt.Sprintf("The DaVinci flow will be accepted by the provider, but the DaVinci Flow Export contains unknown properties that cannot be validated. These parameters will be preserved on import to the DaVinci service, but there may be unpredictable results in difference calculation."),
240+
Message: "The DaVinci flow will be accepted by the provider, but the DaVinci Flow Export contains unknown properties that cannot be validated. These parameters will be preserved on import to the DaVinci service, but there may be unpredictable results in difference calculation.",
241241
Result: output.ENUM_RESULT_NOACTION_WARN,
242242
Fields: map[string]interface{}{
243243
"Computed Difference": unknownAdditionalFieldsError.Diff,
@@ -278,7 +278,7 @@ func (d *DaVinciValidator) OutputValidationResponse(vErr error) (ok, warning boo
278278

279279
case errors.Is(vErr, io.EOF):
280280
outputOpts = output.Opts{
281-
Message: fmt.Sprintf("The export contents cannot be empty"),
281+
Message: "The export contents cannot be empty",
282282
Result: output.ENUM_RESULT_FAILURE,
283283
}
284284

0 commit comments

Comments
 (0)