You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SA1019: simplify rules for deprecated standard library API
In the past, we made use of the AlternativeAvailableSince field. If a
function was deprecated in Go 1.6 and an alternative had been available
in Go 1.0, then we'd recommend using the alternative even if targeting
Go 1.2. The idea was to suggest writing future-proof code by using
already-existing alternatives. This had a major flaw, however: the user
would need to use at least Go 1.6 for Staticcheck to know that the
function had been deprecated. Thus, targeting Go 1.2 and using Go 1.2
would behave differently from targeting Go 1.2 and using Go 1.6. This is
especially a problem if the user tries to ignore the warning. Depending
on the Go version in use, the ignore directive may or may not match,
causing a warning of its own.
To avoid this issue, we no longer try to be smart. We now only compare
the targeted version against the version that deprecated an object.
Closes: gh-1318
(cherry picked from commit 6422635)
Copy file name to clipboardExpand all lines: staticcheck/testdata/src/example.com/CheckDeprecated_go13/CheckDeprecated.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ import (
7
7
)
8
8
9
9
funcfn() {
10
-
filepath.HasPrefix("", "") //@ diag(`filepath.HasPrefix has been deprecated since Go 1.0 because it shouldn't be used:`)
11
-
_=httputil.ErrPersistEOF//@ diag(`httputil.ErrPersistEOF has been deprecated since Go 1.0:`)
12
-
_= httputil.ServerConn{} //@ diag(`httputil.ServerConn has been deprecated since Go 1.0:`)
13
-
_= x509.CertificateRequest{}.Attributes//@ diag(`x509.CertificateRequest{}.Attributes has been deprecated since Go 1.5 and an alternative has been available since Go 1.3:`)
10
+
filepath.HasPrefix("", "") //@ diag(`filepath.HasPrefix has been deprecated since Go 1.0 because it shouldn't be used:`)
11
+
_=httputil.ErrPersistEOF//@ diag(`httputil.ErrPersistEOF has been deprecated since Go 1.0:`)
12
+
_= httputil.ServerConn{} //@ diag(`httputil.ServerConn has been deprecated since Go 1.0:`)
Copy file name to clipboardExpand all lines: staticcheck/testdata/src/example.com/CheckDeprecated_go18/CheckDeprecated.go
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@ package pkg
2
2
3
3
import (
4
4
"compress/flate"
5
+
"crypto/x509"
5
6
"database/sql/driver"
6
7
"net/http"
7
8
"os"
@@ -29,6 +30,8 @@ func fn1(err error) {
29
30
30
31
varconn driver.Conn
31
32
conn.Begin() //@ diag(`Begin has been deprecated`)
33
+
34
+
_= x509.CertificateRequest{}.Attributes//@ diag(`x509.CertificateRequest{}.Attributes has been deprecated since Go 1.5 and an alternative has been available since Go 1.3:`)
0 commit comments