Nonstandard Method Signature

ID

go.nonstandard_method_sig

Severity

low

Remediation Complexity

simple

Remediation Risk

medium

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

reliability

Description

Reports a method whose name belongs to a well-known Go interface but whose signature does not match the one that interface requires.

Rationale

String() string (fmt.Stringer) and Error() string (error) both take no parameters and return a single string. A method named String or Error with a different shape silently fails to satisfy the interface, so the value will not print or format as intended and the bug is easy to miss. The checked names and their expected result types are configurable.

// Bad
func (t T) String(x int) string { return "" } // FLAW — must take no parameters
func (t T) Error() int          { return 0 }  // FLAW — must return a string

// Good
func (t T) String() string { return "" } // OK
func (t T) Error() string  { return "" } // OK

Remediation

Match the standard signature: String() string and Error() string, taking no parameters and returning a single string.