mirror of
https://github.com/golang/go
synced 2024-11-20 01:14:40 -07:00
gofix: make fix order implicit by date.
This partially undoes 8fd7e6d070c8, but preserves its semantics. More importantly, it results in the data about each fix being decentralised, which makes it easier for new fixes to be added, and other gofix users to slot new fixes in. It also adds some useful metadata that could be used in the future. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5306092
This commit is contained in:
parent
37d82c8520
commit
d26144be29
@ -11,11 +11,12 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
fixes = append(fixes, errorFix)
|
||||
register(errorFix)
|
||||
}
|
||||
|
||||
var errorFix = fix{
|
||||
"error",
|
||||
"2011-11-02",
|
||||
errorFn,
|
||||
`Use error instead of os.Error.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(filepathFix)
|
||||
}
|
||||
|
||||
var filepathFix = fix{
|
||||
"filepath",
|
||||
"2011-06-26",
|
||||
filepathFunc,
|
||||
`Adapt code from filepath.[List]SeparatorString to string(filepath.[List]Separator).
|
||||
|
||||
|
@ -24,45 +24,29 @@ import (
|
||||
|
||||
type fix struct {
|
||||
name string
|
||||
date string // date that fix was introduced, in YYYY-MM-DD format
|
||||
f func(*ast.File) bool
|
||||
desc string
|
||||
}
|
||||
|
||||
// main runs sort.Sort(fixes) before printing list of fixes.
|
||||
type fixlist []fix
|
||||
// main runs sort.Sort(byName(fixes)) before printing list of fixes.
|
||||
type byName []fix
|
||||
|
||||
func (f fixlist) Len() int { return len(f) }
|
||||
func (f fixlist) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
func (f fixlist) Less(i, j int) bool { return f[i].name < f[j].name }
|
||||
func (f byName) Len() int { return len(f) }
|
||||
func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
func (f byName) Less(i, j int) bool { return f[i].name < f[j].name }
|
||||
|
||||
var fixes = fixlist{
|
||||
// NOTE: This list must be in chronological order,
|
||||
// so that code using APIs that changed multiple times
|
||||
// can be updated in the correct order.
|
||||
// Add new fixes to bottom of list. Do not sort.
|
||||
httpserverFix,
|
||||
procattrFix,
|
||||
netdialFix,
|
||||
netlookupFix,
|
||||
tlsdialFix,
|
||||
osopenFix,
|
||||
reflectFix,
|
||||
httpFinalURLFix,
|
||||
httpHeadersFix,
|
||||
oserrorstringFix,
|
||||
sortsliceFix,
|
||||
filepathFix,
|
||||
httpFileSystemFix,
|
||||
stringssplitFix,
|
||||
signalFix,
|
||||
sorthelpersFix,
|
||||
urlFix,
|
||||
netudpgroupFix,
|
||||
imagenewFix,
|
||||
mathFix,
|
||||
ioCopyNFix,
|
||||
imagecolorFix,
|
||||
mapdeleteFix,
|
||||
// main runs sort.Sort(byDate(fixes)) before applying fixes.
|
||||
type byDate []fix
|
||||
|
||||
func (f byDate) Len() int { return len(f) }
|
||||
func (f byDate) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
func (f byDate) Less(i, j int) bool { return f[i].date < f[j].date }
|
||||
|
||||
var fixes []fix
|
||||
|
||||
func register(f fix) {
|
||||
fixes = append(fixes, f)
|
||||
}
|
||||
|
||||
// walk traverses the AST x, calling visit(y) for each node y in the tree but
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(httpFinalURLFix)
|
||||
}
|
||||
|
||||
var httpFinalURLFix = fix{
|
||||
"httpfinalurl",
|
||||
"2011-05-13",
|
||||
httpfinalurl,
|
||||
`Adapt http Get calls to not have a finalURL result parameter.
|
||||
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
"go/token"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(httpFileSystemFix)
|
||||
}
|
||||
|
||||
var httpFileSystemFix = fix{
|
||||
"httpfs",
|
||||
"2011-06-27",
|
||||
httpfs,
|
||||
`Adapt http FileServer to take a FileSystem.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(httpHeadersFix)
|
||||
}
|
||||
|
||||
var httpHeadersFix = fix{
|
||||
"httpheaders",
|
||||
"2011-06-16",
|
||||
httpheaders,
|
||||
`Rename http Referer, UserAgent, Cookie, SetCookie, which are now methods.
|
||||
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
"go/token"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(httpserverFix)
|
||||
}
|
||||
|
||||
var httpserverFix = fix{
|
||||
"httpserver",
|
||||
"2011-03-15",
|
||||
httpserver,
|
||||
`Adapt http server methods and functions to changes
|
||||
made to the http ResponseWriter interface.
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(imagecolorFix)
|
||||
}
|
||||
|
||||
var imagecolorFix = fix{
|
||||
"imagecolor",
|
||||
"2011-10-04",
|
||||
imagecolor,
|
||||
`Adapt code to types moved from image to color.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(imagenewFix)
|
||||
}
|
||||
|
||||
var imagenewFix = fix{
|
||||
"imagenew",
|
||||
"2011-09-14",
|
||||
imagenew,
|
||||
`Adapt image.NewXxx calls to pass an image.Rectangle instead of (w, h int).
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(ioCopyNFix)
|
||||
}
|
||||
|
||||
var ioCopyNFix = fix{
|
||||
"iocopyn",
|
||||
"2011-09-30",
|
||||
ioCopyN,
|
||||
`Rename io.Copyn to io.CopyN.
|
||||
|
||||
|
@ -40,7 +40,7 @@ func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: gofix [-diff] [-r fixname,...] [-force fixname,...] [path ...]\n")
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprintf(os.Stderr, "\nAvailable rewrites are:\n")
|
||||
sort.Sort(fixes)
|
||||
sort.Sort(byName(fixes))
|
||||
for _, f := range fixes {
|
||||
fmt.Fprintf(os.Stderr, "\n%s\n", f.name)
|
||||
desc := strings.TrimSpace(f.desc)
|
||||
@ -54,6 +54,8 @@ func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
sort.Sort(byDate(fixes))
|
||||
|
||||
if *allowedRewrites != "" {
|
||||
allowed = make(map[string]bool)
|
||||
for _, f := range strings.Split(*allowedRewrites, ",") {
|
||||
|
@ -6,8 +6,13 @@ package main
|
||||
|
||||
import "go/ast"
|
||||
|
||||
func init() {
|
||||
register(mapdeleteFix)
|
||||
}
|
||||
|
||||
var mapdeleteFix = fix{
|
||||
"mapdelete",
|
||||
"2011-10-18",
|
||||
mapdelete,
|
||||
`Use delete(m, k) instead of m[k] = 0, false.
|
||||
|
||||
|
@ -6,8 +6,13 @@ package main
|
||||
|
||||
import "go/ast"
|
||||
|
||||
func init() {
|
||||
register(mathFix)
|
||||
}
|
||||
|
||||
var mathFix = fix{
|
||||
"math",
|
||||
"2011-09-29",
|
||||
math,
|
||||
`Remove the leading F from math functions such as Fabs.
|
||||
|
||||
|
@ -8,8 +8,15 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(netdialFix)
|
||||
register(tlsdialFix)
|
||||
register(netlookupFix)
|
||||
}
|
||||
|
||||
var netdialFix = fix{
|
||||
"netdial",
|
||||
"2011-03-28",
|
||||
netdial,
|
||||
`Adapt 3-argument calls of net.Dial to use 2-argument form.
|
||||
|
||||
@ -19,6 +26,7 @@ http://codereview.appspot.com/4244055
|
||||
|
||||
var tlsdialFix = fix{
|
||||
"tlsdial",
|
||||
"2011-03-28",
|
||||
tlsdial,
|
||||
`Adapt 4-argument calls of tls.Dial to use 3-argument form.
|
||||
|
||||
@ -28,6 +36,7 @@ http://codereview.appspot.com/4244055
|
||||
|
||||
var netlookupFix = fix{
|
||||
"netlookup",
|
||||
"2011-03-28",
|
||||
netlookup,
|
||||
`Adapt 3-result calls to net.LookupHost to use 2-result form.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(netudpgroupFix)
|
||||
}
|
||||
|
||||
var netudpgroupFix = fix{
|
||||
"netudpgroup",
|
||||
"2011-08-18",
|
||||
netudpgroup,
|
||||
`Adapt 1-argument calls of net.(*UDPConn).JoinGroup, LeaveGroup to use 2-argument form.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(oserrorstringFix)
|
||||
}
|
||||
|
||||
var oserrorstringFix = fix{
|
||||
"oserrorstring",
|
||||
"2011-06-22",
|
||||
oserrorstring,
|
||||
`Replace os.ErrorString() conversions with calls to os.NewError().
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(osopenFix)
|
||||
}
|
||||
|
||||
var osopenFix = fix{
|
||||
"osopen",
|
||||
"2011-04-04",
|
||||
osopen,
|
||||
`Adapt os.Open calls to new, easier API and rename O_CREAT O_CREATE.
|
||||
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
"go/token"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(procattrFix)
|
||||
}
|
||||
|
||||
var procattrFix = fix{
|
||||
"procattr",
|
||||
"2011-03-15",
|
||||
procattr,
|
||||
`Adapt calls to os.StartProcess to use new ProcAttr type.
|
||||
|
||||
|
@ -15,8 +15,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(reflectFix)
|
||||
}
|
||||
|
||||
var reflectFix = fix{
|
||||
"reflect",
|
||||
"2011-04-08",
|
||||
reflectFn,
|
||||
`Adapt code to new reflect API.
|
||||
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(signalFix)
|
||||
}
|
||||
|
||||
var signalFix = fix{
|
||||
"signal",
|
||||
"2011-06-29",
|
||||
signal,
|
||||
`Adapt code to types moved from os/signal to signal.
|
||||
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(sorthelpersFix)
|
||||
}
|
||||
|
||||
var sorthelpersFix = fix{
|
||||
"sorthelpers",
|
||||
"2011-07-08",
|
||||
sorthelpers,
|
||||
`Adapt code from sort.Sort[Ints|Float64s|Strings] to sort.[Ints|Float64s|Strings].
|
||||
`,
|
||||
|
@ -8,8 +8,13 @@ import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(sortsliceFix)
|
||||
}
|
||||
|
||||
var sortsliceFix = fix{
|
||||
"sortslice",
|
||||
"2011-06-26",
|
||||
sortslice,
|
||||
`Adapt code from sort.[Float64|Int|String]Array to sort.[Float64|Int|String]Slice.
|
||||
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
"go/token"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(stringssplitFix)
|
||||
}
|
||||
|
||||
var stringssplitFix = fix{
|
||||
"stringssplit",
|
||||
"2011-06-28",
|
||||
stringssplit,
|
||||
`Restore strings.Split to its original meaning and add strings.SplitN. Bytes too.
|
||||
|
||||
|
@ -6,8 +6,13 @@ package main
|
||||
|
||||
import "go/ast"
|
||||
|
||||
func init() {
|
||||
register(urlFix)
|
||||
}
|
||||
|
||||
var urlFix = fix{
|
||||
"url",
|
||||
"2011-08-17",
|
||||
url,
|
||||
`Move the URL pieces of package http into a new package, url.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user