package gorules
import (
"github.com/quasilyte/go-ruleguard/dsl"
)
// Some rules require particular Go features to be available.
// For example, `ioutil` package was deprecated in 1.16.
// We can't suggest `ioutil` alternatives unless the target
// Go version is at least 1.16. It would be annoying to
// get the warning that is not actionable for you.
func ioutilDeprecated(m dsl.Matcher) {
// GreaterEqThan performs a "version >= x" check.
m.Match(`ioutil.ReadAll($r)`).
Where(m.GoVersion().GreaterEqThan("1.16")).
Suggest(`io.ReadAll($r)`).
Report(`ioutil.ReadAll is deprecated, use io.ReadAll instead`)
}
package main
import (
"io"
"io/ioutil"
)
func example(r io.Reader) {
ioutil.ReadAll(r)
}
Notes:
==
, <
, >
and so on&&
in combination with GoVersion
methods to create a version range constraint