Skip to content

Commit 4a9e3c6

Browse files
authored
chore: Enable wastedassign linter (#1645)
Catch coding issues before merge, such as #1644. Previous reports before code fixes: ``` cmd/configure.go:725:6: assigned to err, but reassigned without using the value (wastedassign) wf, err := run.NewWorkflow( ^ cmd/lint/lint.go:176:9: assigned to err, but reassigned without using the value (wastedassign) wf, _, err := utils.GetWorkflowAndDir() ^ cmd/quickstart.go:482:6: assigned to err, but reassigned without using the value (wastedassign) wf, err := run.NewWorkflow( ^ cmd/tag.go:101:12: assigned to err, but reassigned without using the value (wastedassign) lockfile, err := workflow.LoadLockfile(projectDir) ^ cmd/testcmd.go:90:2: assigned to target, but reassigned without using the value (wastedassign) target := "" ^ internal/charm/styles/styles.go:171:2: assigned to line, but reassigned without using the value (wastedassign) line := "" ^ internal/github/github.go:131:2: assigned to prMD, but reassigned without using the value (wastedassign) prMD := "" ^ internal/github/github.go:161:2: assigned to md, but reassigned without using the value (wastedassign) md := "" ^ internal/model/command.go:189:2: assigned to short, but never used afterwards (wastedassign) short = utils.CapitalizeFirst(short) ^ internal/run/sourceTracking.go:106:2: assigned to oldRegistryLocation, but reassigned without using the value (wastedassign) oldRegistryLocation := "" ^ internal/studio/studioHelpers.go:515:3: assigned to sdkPath, but reassigned without using the value (wastedassign) sdkPath := "" ^ internal/suggest/errorCodes/errorCodes_test.go:29:13: assigned to err, but reassigned without using the value (wastedassign) overlay, err := errorCodes.BuildErrorCodesOverlay(ctx, tt.in) ^ internal/usagegen/usagegen.go:228:2: assigned to outFile, but reassigned without using the value (wastedassign) outFile := "" ^ internal/validation/openapi.go:171:3: assigned to s, but reassigned without using the value (wastedassign) s := "" ^ internal/workflowTracking/workflowTracking.go:161:6: assigned to status, but reassigned without using the value (wastedassign) var status Status = StatusSucceeded ^ pkg/merge/merge_test.go:35:8: assigned to err, but reassigned without using the value (wastedassign) got1, err := merge(absSchemas, true) ^ pkg/merge/merge_test.go:36:8: assigned to err, but reassigned without using the value (wastedassign) got2, err := merge(absSchemas, true) ^ pkg/transform/cleanup.go:68:17: assigned to err, but never used afterwards (wastedassign) docNew, model, err := openapi.Load(updatedDoc, doc.GetConfiguration().BasePath) ^ prompts/configs.go:156:4: assigned to schemaPath, but reassigned without using the value (wastedassign) schemaPath := "" ^ prompts/github.go:296:2: assigned to prior, but reassigned without using the value (wastedassign) prior := "" ^ 20 issues: * wastedassign: 20 ```
1 parent 2eca151 commit 4a9e3c6

File tree

18 files changed

+35
-24
lines changed

18 files changed

+35
-24
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ linters:
3333
# - unused
3434
# - usestdlibvars
3535
# - usetesting
36-
# - wastedassign
36+
- wastedassign

cmd/configure.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ func configureTesting(ctx context.Context, flags ConfigureTestsFlags) error {
728728
run.WithBoostrapTests(),
729729
)
730730

731+
if err != nil {
732+
return fmt.Errorf("failed to parse workflow: %w", err)
733+
}
734+
731735
if err = wf.RunWithVisualization(ctx); err != nil {
732736
return errors.Wrapf(err, "failed to generate tests")
733737
}

cmd/lint/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func lintOpenapiInteractive(ctx context.Context, flags LintOpenapiFlags) error {
174174
func lintConfig(ctx context.Context, flags lintConfigFlags) error {
175175
// To support the old version of this command, check if there is no workflow.yaml. If there isn't, run the old version
176176
wf, _, err := utils.GetWorkflowAndDir()
177-
if wf == nil {
177+
if wf == nil || err != nil {
178178
log.From(ctx).Info("No workflow.yaml found, running legacy version of this command...")
179179
return sdkgen.ValidateConfig(ctx, flags.Dir)
180180
}

cmd/quickstart.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ func retryWithSampleSpec(ctx context.Context, workflowFile *workflow.Workflow, i
485485
run.WithShouldCompile(!skipCompile),
486486
)
487487

488+
if err != nil {
489+
return false, fmt.Errorf("failed to parse workflow: %w", err)
490+
}
491+
488492
// Execute the workflow based on output mode
489493
switch output {
490494
case "summary":

cmd/testcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func testCmdRunnerOpts(flags testCmdFlags) ([]testcmd.RunnerOpt, error) {
8787
return nil, err
8888
}
8989

90-
target := ""
90+
var target string
9191

9292
if flags.Target == "" {
9393
if len(wf.Targets) == 1 {

internal/charm/styles/styles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func MakeSection(title, content string, color lipgloss.AdaptiveColor) string {
168168
func MakeBreak(heading string, character rune, color lipgloss.AdaptiveColor, isStart bool) string {
169169
termWidth := TerminalWidth()
170170

171-
line := ""
171+
var line string
172172
if heading == "" {
173173
line = strings.Repeat(string(character), termWidth)
174174
} else {

internal/github/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func GenerateChangesSummary(ctx context.Context, url string, summary changes.Sum
128128
}
129129
log.From(ctx).Infof("wrote changes summary to \"%s\"", filepath)
130130
}
131-
prMD := ""
131+
var prMD string
132132
if len(summary.Text) > 0 {
133133
prMD = "<details>\n<summary>OpenAPI Change Summary</summary>\n" + summary.Text + "\n" + "</details>\n"
134134
} else {
@@ -158,7 +158,7 @@ func GenerateWorkflowSummary(ctx context.Context, summary WorkflowSummary) {
158158
}
159159

160160
logger := log.From(ctx)
161-
md := ""
161+
var md string
162162
chart, err := summary.ToMermaidDiagram()
163163
if err == nil {
164164
md = fmt.Sprintf("# Generation Workflow Summary\n\n_This is a breakdown of the 'Generate Target' step above_\n%s", chart)

internal/model/command.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ func (c ExecutableCommand[F]) Init() (*cobra.Command, error) {
185185
return nil, err
186186
}
187187

188-
short := strings.Trim(c.Short, " .")
189-
short = utils.CapitalizeFirst(short)
190-
191188
cmd := &cobra.Command{
192189
Use: c.Usage,
193190
Short: c.Short,

internal/run/sourceTracking.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (w *Workflow) computeChanges(ctx context.Context, rootStep *workflowTrackin
103103
orgSlug := auth.GetOrgSlugFromContext(ctx)
104104
workspaceSlug := auth.GetWorkspaceSlugFromContext(ctx)
105105

106-
oldRegistryLocation := ""
106+
var oldRegistryLocation string
107107
if targetLock.SourceRevisionDigest != "" && targetLock.SourceNamespace != "" {
108108
oldRegistryLocation = fmt.Sprintf("%s/%s/%s/%s@%s", "registry.speakeasyapi.dev", orgSlug, workspaceSlug,
109109
targetLock.SourceNamespace, targetLock.SourceRevisionDigest)

internal/studio/studioHelpers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,11 @@ func updateSourceAndTarget(workflowRunner run.Workflow, sourceID, overlayPath st
512512
}
513513

514514
for targetID, input := range runRequestBody.Targets {
515-
sdkPath := ""
516-
517515
wfTarget, ok := workflowRunner.GetWorkflowFile().Targets[targetID]
518516
if !ok {
519517
return overlayPath, errors.ErrBadRequest.Wrap(fmt.Errorf("target %s not found", targetID))
520518
}
521-
sdkPath = workflowRunner.ProjectDir
519+
sdkPath := workflowRunner.ProjectDir
522520
if wfTarget.Output != nil {
523521
sdkPath = filepath.Join(sdkPath, *wfTarget.Output)
524522
}

0 commit comments

Comments
 (0)