A method has the name of a standard interface's method but another signature, so it is not used
What it finds
func (c Config) MarshalJSON() string: the standard library finds methods such as MarshalJSON, UnmarshalText or WriteTo through interfaces, which match only the exact signature. A method of the right name with another signature is silently not used: encoding/json encodes the fields instead, and io.Copy takes the slow path.
Checked are methods with the names of well-known interfaces of encoding, encoding/json, encoding/gob and io, in a file that imports the package their signature names, if it names one. Parameters and results are compared by their types as written, so io.Reader must be spelled that way.
From the rule's source, misdeclared_standard_method.rs.
package p import "io" type kind int func (k kind) MarshalJSON() string {tx0 reports: MarshalJSON does not have the signature MarshalJSON() ([]byte, error) return ""} func (k *kind) UnmarshalJSON(data []byte) error { return nil} func (k kind) WriteTo(w io.Writer) error {tx0 reports: WriteTo does not have the signature WriteTo(io.Writer) (int64, error) return nil} func (k kind) ReadFrom(r io.Reader) (n int64, err error) { return 0, nil} func (k kind) ReadByte() byte {tx0 reports: ReadByte does not have the signature return 0} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:misdeclared-standard-method" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:misdeclared-standard-method] reason="..."tx0 explain tx0/go:misdeclared-standard-method shows the same in the terminal. Found a false positive? Report it.