Skip to content

Commit 22ea9e5

Browse files
vojtabiberleclaude
andcommitted
DMD-921 - Refactor nil checks to use default-first pattern
Use idiomatic Go pattern: set default value first, then override if present. This avoids the anti-pattern of resetting nil values after assignment. - bucketTables lookup uses comma-ok idiom - Dependencies fields only assigned if not nil Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f43e747 commit 22ea9e5

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

internal/pkg/llm/twinformat/generator.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ func (g *Generator) buildBucketIndex(data *ProcessedData) map[string]any {
185185
for _, bucket := range data.Buckets {
186186
// Extract bucket name from BucketID.
187187
bucketName := extractBucketName(bucket.BucketID.String())
188-
tables := bucketTables[bucketName]
189-
if tables == nil {
190-
tables = []string{}
188+
tables := []string{}
189+
if value, ok := bucketTables[bucketName]; ok {
190+
tables = value
191191
}
192192
buckets = append(buckets, map[string]any{
193193
"name": bucketName,
@@ -253,14 +253,12 @@ func (g *Generator) generateTableMetadata(ctx context.Context, table *ProcessedT
253253
consumedBy := []string{}
254254
producedBy := []string{}
255255
if table.Dependencies != nil {
256-
consumedBy = table.Dependencies.ConsumedBy
257-
producedBy = table.Dependencies.ProducedBy
258-
}
259-
if consumedBy == nil {
260-
consumedBy = []string{}
261-
}
262-
if producedBy == nil {
263-
producedBy = []string{}
256+
if table.Dependencies.ConsumedBy != nil {
257+
consumedBy = table.Dependencies.ConsumedBy
258+
}
259+
if table.Dependencies.ProducedBy != nil {
260+
producedBy = table.Dependencies.ProducedBy
261+
}
264262
}
265263

266264
metadata["dependencies"] = map[string]any{
@@ -423,14 +421,12 @@ func (g *Generator) generateTransformationMetadata(ctx context.Context, transfor
423421
consumes := []string{}
424422
produces := []string{}
425423
if transform.Dependencies != nil {
426-
consumes = transform.Dependencies.Consumes
427-
produces = transform.Dependencies.Produces
428-
}
429-
if consumes == nil {
430-
consumes = []string{}
431-
}
432-
if produces == nil {
433-
produces = []string{}
424+
if transform.Dependencies.Consumes != nil {
425+
consumes = transform.Dependencies.Consumes
426+
}
427+
if transform.Dependencies.Produces != nil {
428+
produces = transform.Dependencies.Produces
429+
}
434430
}
435431

436432
metadata["dependencies"] = map[string]any{

0 commit comments

Comments
 (0)