A member of the standard library that its documentation marks as deprecated is used

tx0/go:deprecated-standard-apistrictwarningmaintainability

What it finds

ioutil.ReadFile(path) or strings.Title(name): the standard library marks some of its functions as deprecated when a better replacement exists, because they are unsafe, wrong for some inputs, or merely moved. They keep working, but their documentation names what to use instead, and some, such as x509.DecryptPEMBlock, are insecure.

Reported are uses of deprecated members of the standard library, resolved through the imports: the functions of io/ioutil, strings.Title, bytes.Title, rand.Seed and rand.Read of math/rand, x509.IsEncryptedPEMBlock, x509.DecryptPEMBlock, x509.EncryptPEMBlock, os.SEEK_SET, os.SEEK_CUR, os.SEEK_END, reflect.SliceHeader, reflect.StringHeader, http.ErrWriteAfterFlush, elliptic.Marshal, elliptic.Unmarshal, elliptic.GenerateKey, a few of syscall, go/importer and net/http/httputil, and calls of a method InterfaceData without arguments in a file that imports reflect. Code that still supports old Go versions may need some of them, so the rule is strict.

From the rule's source, deprecated_standard_api.rs.

Example from the rule's tests
package p import (	"io/ioutil"	"os"	"reflect"	"strings") func f(path string, v reflect.Value) (string, error) {	data, err := ioutil.ReadFile(path)tx0 reports: ioutil.ReadFile is deprecated	_ = v.InterfaceData()tx0 reports: v.InterfaceData() is deprecated	_, _ = os.ReadFile(path)	return strings.Title(string(data)), errtx0 reports: strings.Title is deprecated}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:deprecated-standard-api" = "warning"

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:deprecated-standard-api] reason="..."

tx0 explain tx0/go:deprecated-standard-api shows the same in the terminal. Found a false positive? Report it.