Get Return

ID

go.get_return

Severity

low

Remediation Complexity

simple

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Go

Tags

naming

Description

Reports a function or method whose name starts with Get / get but which returns nothing, or returns only an error.

Rationale

A Get prefix advertises an accessor that yields a value. A getter that returns no usable value contradicts its own name and is almost always either misnamed (it is really an action or command) or missing its result. A getter that returns a value alongside an error ((T, error)) is fine.

// Bad
func GetName()       {}            // FLAW — returns nothing
func GetErr() error  { return nil }// FLAW — returns only an error

// Good
func GetCount() int        { return 0 }       // OK
func GetItem() (string, error) { return "", nil } // OK

Remediation

Return the value the getter accesses, or rename the function to reflect that it performs an action rather than reading a value.