github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/knowledge/deprecated.go (about)

     1  package knowledge
     2  
     3  const (
     4  	// DeprecatedNeverUse indicates that an API should never be used, regardless of Go version.
     5  	DeprecatedNeverUse = -1
     6  	// DeprecatedUseNoLonger indicates that an API has no use anymore.
     7  	DeprecatedUseNoLonger = -2
     8  )
     9  
    10  // Deprecation describes when a Go API has been deprecated.
    11  type Deprecation struct {
    12  	// The minor Go version since which this API has been deprecated.
    13  	DeprecatedSince int
    14  	// The minor Go version since which an alternative API has been available.
    15  	// May also be one of DeprecatedNeverUse or DeprecatedUseNoLonger.
    16  	AlternativeAvailableSince int
    17  }
    18  
    19  // go/importer.ForCompiler contains "Deprecated:", but it refers to a single argument, not the whole function.
    20  // Luckily, the notice starts in the middle of a paragraph, and as such isn't detected by us.
    21  
    22  // TODO(dh): StdlibDeprecations doesn't contain entries for internal packages and unexported API. That's fine for normal
    23  // users, but makes the Deprecated check less useful for people working on Go itself.
    24  
    25  // StdlibDeprecations contains a mapping of Go API (such as variables, methods, or fields, among others)
    26  // to information about when it has been deprecated.
    27  var StdlibDeprecations = map[string]Deprecation{
    28  	// FIXME(dh): AllowBinary isn't being detected as deprecated
    29  	// because the comment has a newline right after "Deprecated:"
    30  	"go/build.AllowBinary":                      {7, 7},
    31  	"(archive/zip.FileHeader).CompressedSize":   {1, 1},
    32  	"(archive/zip.FileHeader).UncompressedSize": {1, 1},
    33  	"(archive/zip.FileHeader).ModifiedTime":     {10, 10},
    34  	"(archive/zip.FileHeader).ModifiedDate":     {10, 10},
    35  	"(*archive/zip.FileHeader).ModTime":         {10, 10},
    36  	"(*archive/zip.FileHeader).SetModTime":      {10, 10},
    37  	"(go/doc.Package).Bugs":                     {1, 1},
    38  	"os.SEEK_SET":                               {7, 7},
    39  	"os.SEEK_CUR":                               {7, 7},
    40  	"os.SEEK_END":                               {7, 7},
    41  	"(net.Dialer).Cancel":                       {7, 7},
    42  	"runtime.CPUProfile":                        {9, 0},
    43  	"compress/flate.ReadError":                  {6, DeprecatedUseNoLonger},
    44  	"compress/flate.WriteError":                 {6, DeprecatedUseNoLonger},
    45  	"path/filepath.HasPrefix":                   {0, DeprecatedNeverUse},
    46  	"(net/http.Transport).Dial":                 {7, 7},
    47  	"(net/http.Transport).DialTLS":              {14, 14},
    48  	"(*net/http.Transport).CancelRequest":       {6, 5},
    49  	"net/http.ErrWriteAfterFlush":               {7, DeprecatedUseNoLonger},
    50  	"net/http.ErrHeaderTooLong":                 {8, DeprecatedUseNoLonger},
    51  	"net/http.ErrShortBody":                     {8, DeprecatedUseNoLonger},
    52  	"net/http.ErrMissingContentLength":          {8, DeprecatedUseNoLonger},
    53  	"net/http/httputil.ErrPersistEOF":           {0, DeprecatedUseNoLonger},
    54  	"net/http/httputil.ErrClosed":               {0, DeprecatedUseNoLonger},
    55  	"net/http/httputil.ErrPipeline":             {0, DeprecatedUseNoLonger},
    56  	"net/http/httputil.ServerConn":              {0, 0},
    57  	"net/http/httputil.NewServerConn":           {0, 0},
    58  	"net/http/httputil.ClientConn":              {0, 0},
    59  	"net/http/httputil.NewClientConn":           {0, 0},
    60  	"net/http/httputil.NewProxyClientConn":      {0, 0},
    61  	"(net/http.Request).Cancel":                 {7, 7},
    62  	"(text/template/parse.PipeNode).Line":       {1, DeprecatedUseNoLonger},
    63  	"(text/template/parse.ActionNode).Line":     {1, DeprecatedUseNoLonger},
    64  	"(text/template/parse.BranchNode).Line":     {1, DeprecatedUseNoLonger},
    65  	"(text/template/parse.TemplateNode).Line":   {1, DeprecatedUseNoLonger},
    66  	"database/sql/driver.ColumnConverter":       {9, 9},
    67  	"database/sql/driver.Execer":                {8, 8},
    68  	"database/sql/driver.Queryer":               {8, 8},
    69  	"(database/sql/driver.Conn).Begin":          {8, 8},
    70  	"(database/sql/driver.Stmt).Exec":           {8, 8},
    71  	"(database/sql/driver.Stmt).Query":          {8, 8},
    72  	"syscall.StringByteSlice":                   {1, 1},
    73  	"syscall.StringBytePtr":                     {1, 1},
    74  	"syscall.StringSlicePtr":                    {1, 1},
    75  	"syscall.StringToUTF16":                     {1, 1},
    76  	"syscall.StringToUTF16Ptr":                  {1, 1},
    77  	"(*regexp.Regexp).Copy":                     {12, DeprecatedUseNoLonger},
    78  	"(archive/tar.Header).Xattrs":               {10, 10},
    79  	"archive/tar.TypeRegA":                      {11, 1},
    80  	"go/types.NewInterface":                     {11, 11},
    81  	"(*go/types.Interface).Embedded":            {11, 11},
    82  	"go/importer.For":                           {12, 12},
    83  	"encoding/json.InvalidUTF8Error":            {2, DeprecatedUseNoLonger},
    84  	"encoding/json.UnmarshalFieldError":         {2, DeprecatedUseNoLonger},
    85  	"encoding/csv.ErrTrailingComma":             {2, DeprecatedUseNoLonger},
    86  	"(encoding/csv.Reader).TrailingComma":       {2, DeprecatedUseNoLonger},
    87  	"(net.Dialer).DualStack":                    {12, 12},
    88  	"net/http.ErrUnexpectedTrailer":             {12, DeprecatedUseNoLonger},
    89  	"net/http.CloseNotifier":                    {11, 7},
    90  	// This is hairy. The notice says "Not all errors in the http package related to protocol errors are of type ProtocolError", but doesn't that imply that some errors do?
    91  	"net/http.ProtocolError":                       {8, DeprecatedUseNoLonger},
    92  	"(crypto/x509.CertificateRequest).Attributes":  {5, 3},
    93  	"(*crypto/x509.Certificate).CheckCRLSignature": {19, 19},
    94  	"crypto/x509.ParseCRL":                         {19, 19},
    95  	"crypto/x509.ParseDERCRL":                      {19, 19},
    96  	"(*crypto/x509.Certificate).CreateCRL":         {19, 19},
    97  	"crypto/x509/pkix.TBSCertificateList":          {19, 19},
    98  	"crypto/x509/pkix.RevokedCertificate":          {19, 19},
    99  	"go/doc.ToHTML":                                {20, 20},
   100  	"go/doc.ToText":                                {20, 20},
   101  	"go/doc.Synopsis":                              {20, 20},
   102  	"math/rand.Seed":                               {20, 0},
   103  	"math/rand.Read":                               {20, DeprecatedNeverUse},
   104  
   105  	// These functions have no direct alternative, but they are insecure and should no longer be used.
   106  	"crypto/x509.IsEncryptedPEMBlock": {16, DeprecatedNeverUse},
   107  	"crypto/x509.DecryptPEMBlock":     {16, DeprecatedNeverUse},
   108  	"crypto/x509.EncryptPEMBlock":     {16, DeprecatedNeverUse},
   109  	"crypto/dsa":                      {16, DeprecatedNeverUse},
   110  
   111  	// This function has no alternative, but also no purpose.
   112  	"(*crypto/rc4.Cipher).Reset":                     {12, DeprecatedNeverUse},
   113  	"(net/http/httptest.ResponseRecorder).HeaderMap": {11, 7},
   114  	"image.ZP":                                    {13, 0},
   115  	"image.ZR":                                    {13, 0},
   116  	"(*debug/gosym.LineTable).LineToPC":           {2, 2},
   117  	"(*debug/gosym.LineTable).PCToLine":           {2, 2},
   118  	"crypto/tls.VersionSSL30":                     {13, DeprecatedNeverUse},
   119  	"(crypto/tls.Config).NameToCertificate":       {14, DeprecatedUseNoLonger},
   120  	"(*crypto/tls.Config).BuildNameToCertificate": {14, DeprecatedUseNoLonger},
   121  	"(crypto/tls.Config).SessionTicketKey":        {16, 5},
   122  	// No alternative, no use
   123  	"(crypto/tls.ConnectionState).NegotiatedProtocolIsMutual": {16, DeprecatedNeverUse},
   124  	// No alternative, but insecure
   125  	"(crypto/tls.ConnectionState).TLSUnique": {16, DeprecatedNeverUse},
   126  	"image/jpeg.Reader":                      {4, DeprecatedNeverUse},
   127  
   128  	// All of these have been deprecated in favour of external libraries
   129  	"syscall.AttachLsf":                     {7, 0},
   130  	"syscall.DetachLsf":                     {7, 0},
   131  	"syscall.LsfSocket":                     {7, 0},
   132  	"syscall.SetLsfPromisc":                 {7, 0},
   133  	"syscall.LsfJump":                       {7, 0},
   134  	"syscall.LsfStmt":                       {7, 0},
   135  	"syscall.BpfStmt":                       {7, 0},
   136  	"syscall.BpfJump":                       {7, 0},
   137  	"syscall.BpfBuflen":                     {7, 0},
   138  	"syscall.SetBpfBuflen":                  {7, 0},
   139  	"syscall.BpfDatalink":                   {7, 0},
   140  	"syscall.SetBpfDatalink":                {7, 0},
   141  	"syscall.SetBpfPromisc":                 {7, 0},
   142  	"syscall.FlushBpf":                      {7, 0},
   143  	"syscall.BpfInterface":                  {7, 0},
   144  	"syscall.SetBpfInterface":               {7, 0},
   145  	"syscall.BpfTimeout":                    {7, 0},
   146  	"syscall.SetBpfTimeout":                 {7, 0},
   147  	"syscall.BpfStats":                      {7, 0},
   148  	"syscall.SetBpfImmediate":               {7, 0},
   149  	"syscall.SetBpf":                        {7, 0},
   150  	"syscall.CheckBpfVersion":               {7, 0},
   151  	"syscall.BpfHeadercmpl":                 {7, 0},
   152  	"syscall.SetBpfHeadercmpl":              {7, 0},
   153  	"syscall.RouteRIB":                      {8, 0},
   154  	"syscall.RoutingMessage":                {8, 0},
   155  	"syscall.RouteMessage":                  {8, 0},
   156  	"syscall.InterfaceMessage":              {8, 0},
   157  	"syscall.InterfaceAddrMessage":          {8, 0},
   158  	"syscall.ParseRoutingMessage":           {8, 0},
   159  	"syscall.ParseRoutingSockaddr":          {8, 0},
   160  	"syscall.InterfaceAnnounceMessage":      {7, 0},
   161  	"syscall.InterfaceMulticastAddrMessage": {7, 0},
   162  	"syscall.FormatMessage":                 {5, 0},
   163  	"syscall.PostQueuedCompletionStatus":    {17, 0},
   164  	"syscall.GetQueuedCompletionStatus":     {17, 0},
   165  	"syscall.CreateIoCompletionPort":        {17, 0},
   166  
   167  	// We choose to only track the package itself, even though all functions are derecated individually, too. Anyone
   168  	// using ioutil directly will have to import it, and this keeps the noise down.
   169  	"io/ioutil": {19, 19},
   170  
   171  	"bytes.Title":   {18, 0},
   172  	"strings.Title": {18, 0},
   173  	"(crypto/tls.Config).PreferServerCipherSuites": {18, DeprecatedUseNoLonger},
   174  	// It's not clear if Subjects was okay to use in the past, so we err on the less noisy side of assuming that it was.
   175  	"(*crypto/x509.CertPool).Subjects": {18, DeprecatedUseNoLonger},
   176  	"go/types.NewSignature":            {18, 18},
   177  	"(net.Error).Temporary":            {18, DeprecatedNeverUse},
   178  	// InterfaceData is another tricky case. It was deprecated in Go 1.18, but has been useless since Go 1.4, and an
   179  	// "alternative" (using your own unsafe hacks) has existed forever. We don't want to get into hairsplitting with
   180  	// users who somehow successfully used this between 1.4 and 1.18, so we'll just tag it as deprecated since 1.18.
   181  	"(reflect.Value).InterfaceData": {18, 18},
   182  
   183  	// The following objects are only deprecated on Windows.
   184  	"syscall.Syscall":   {18, 18},
   185  	"syscall.Syscall12": {18, 18},
   186  	"syscall.Syscall15": {18, 18},
   187  	"syscall.Syscall18": {18, 18},
   188  	"syscall.Syscall6":  {18, 18},
   189  	"syscall.Syscall9":  {18, 18},
   190  
   191  	"reflect.SliceHeader":                              {21, 17},
   192  	"reflect.StringHeader":                             {21, 20},
   193  	"crypto/elliptic.GenerateKey":                      {21, 21},
   194  	"crypto/elliptic.Marshal":                          {21, 21},
   195  	"crypto/elliptic.Unmarshal":                        {21, 21},
   196  	"(*crypto/elliptic.CurveParams).Add":               {21, 21},
   197  	"(*crypto/elliptic.CurveParams).Double":            {21, 21},
   198  	"(*crypto/elliptic.CurveParams).IsOnCurve":         {21, 21},
   199  	"(*crypto/elliptic.CurveParams).ScalarBaseMult":    {21, 21},
   200  	"(*crypto/elliptic.CurveParams).ScalarMult":        {21, 21},
   201  	"crypto/rsa.GenerateMultiPrimeKey":                 {21, DeprecatedNeverUse},
   202  	"(crypto/rsa.PrecomputedValues).CRTValues":         {21, DeprecatedNeverUse},
   203  	"(crypto/x509.RevocationList).RevokedCertificates": {21, 21},
   204  }
   205  
   206  // Last imported from Go at c19c4c566c63818dfd059b352e52c4710eecf14d with the following numbers of deprecations:
   207  //
   208  // archive/tar/common.go:2
   209  // archive/zip/struct.go:6
   210  // bytes/bytes.go:1
   211  // compress/flate/inflate.go:2
   212  // crypto/dsa/dsa.go:1
   213  // crypto/elliptic/elliptic.go:8
   214  // crypto/elliptic/params.go:5
   215  // crypto/rc4/rc4.go:1
   216  // crypto/rsa/rsa.go:2
   217  // crypto/tls/common.go:6
   218  // crypto/x509/cert_pool.go:1
   219  // crypto/x509/pem_decrypt.go:3
   220  // crypto/x509/pkix/pkix.go:2
   221  // crypto/x509/x509.go:6
   222  // database/sql/driver/driver.go:6
   223  // debug/gosym/pclntab.go:2
   224  // encoding/csv/reader.go:2
   225  // encoding/json/decode.go:1
   226  // encoding/json/encode.go:1
   227  // go/build/build.go:1
   228  // go/doc/comment.go:2
   229  // go/doc/doc.go:1
   230  // go/doc/synopsis.go:1
   231  // go/importer/importer.go:2
   232  // go/types/interface.go:2
   233  // go/types/signature.go:1
   234  // image/geom.go:2
   235  // image/jpeg/reader.go:1
   236  // internal/types/errors/codes.go:1
   237  // io/ioutil/ioutil.go:7
   238  // io/ioutil/tempfile.go:2
   239  // math/rand/rand.go:2
   240  // net/dial.go:2
   241  // net/http/h2_bundle.go:1
   242  // net/http/httptest/recorder.go:1
   243  // net/http/httputil/persist.go:8
   244  // net/http/request.go:6
   245  // net/http/server.go:2
   246  // net/http/socks_bundle.go:1
   247  // net/http/transport.go:3
   248  // net/net.go:1
   249  // os/file.go:1
   250  // path/filepath/path_plan9.go:1
   251  // path/filepath/path_unix.go:1
   252  // path/filepath/path_windows.go:1
   253  // reflect/value.go:3
   254  // regexp/regexp.go:1
   255  // runtime/cpuprof.go:1
   256  // strings/strings.go:1
   257  // syscall/bpf_bsd.go:18
   258  // syscall/bpf_darwin.go:18
   259  // syscall/dll_windows.go:6
   260  // syscall/exec_plan9.go:1
   261  // syscall/exec_unix.go:1
   262  // syscall/lsf_linux.go:6
   263  // syscall/route_bsd.go:7
   264  // syscall/route_darwin.go:1
   265  // syscall/route_dragonfly.go:2
   266  // syscall/route_freebsd.go:2
   267  // syscall/route_netbsd.go:1
   268  // syscall/route_openbsd.go:1
   269  // syscall/syscall.go:3
   270  // syscall/syscall_windows.go:6
   271  // text/template/parse/node.go:5
   272  // vendor/golang.org/x/text/transform/transform.go:1