--- /dev/null
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "go/ast"
+)
+
+func init() {
+ register(contextFix)
+}
+
+var contextFix = fix{
+ name: "context",
+ date: "2016-09-09",
+ f: ctxfix,
+ desc: `Change imports of golang.org/x/net/context to context`,
+ disabled: true,
+}
+
+func ctxfix(f *ast.File) bool {
+ return rewriteImport(f, "golang.org/x/net/context", "context")
+}
--- /dev/null
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+ addTestCases(contextTests, ctxfix)
+}
+
+var contextTests = []testCase{
+ {
+ Name: "context.0",
+ In: `package main
+
+import "golang.org/x/net/context"
+
+var _ = "golang.org/x/net/context"
+`,
+ Out: `package main
+
+import "context"
+
+var _ = "golang.org/x/net/context"
+`,
+ },
+ {
+ Name: "context.1",
+ In: `package main
+
+import ctx "golang.org/x/net/context"
+
+var _ = ctx.Background()
+`,
+ Out: `package main
+
+import ctx "context"
+
+var _ = ctx.Background()
+`,
+ },
+}
)
type fix struct {
- name string
- date string // date that fix was introduced, in YYYY-MM-DD format
- f func(*ast.File) bool
- desc string
+ name string
+ date string // date that fix was introduced, in YYYY-MM-DD format
+ f func(*ast.File) bool
+ desc string
+ disabled bool // whether this fix should be disabled by default
}
// main runs sort.Sort(byName(fixes)) before printing list of fixes.
}
var gotypesFix = fix{
- "gotypes",
- "2015-07-16",
- gotypes,
- `Change imports of golang.org/x/tools/go/{exact,types} to go/{constant,types}`,
+ name: "gotypes",
+ date: "2015-07-16",
+ f: gotypes,
+ desc: `Change imports of golang.org/x/tools/go/{exact,types} to go/{constant,types}`,
}
func gotypes(f *ast.File) bool {
fmt.Fprintf(os.Stderr, "\nAvailable rewrites are:\n")
sort.Sort(byName(fixes))
for _, f := range fixes {
- fmt.Fprintf(os.Stderr, "\n%s\n", f.name)
+ if f.disabled {
+ fmt.Fprintf(os.Stderr, "\n%s (disabled)\n", f.name)
+ } else {
+ fmt.Fprintf(os.Stderr, "\n%s\n", f.name)
+ }
desc := strings.TrimSpace(f.desc)
desc = strings.Replace(desc, "\n", "\n\t", -1)
fmt.Fprintf(os.Stderr, "\t%s\n", desc)
if allowed != nil && !allowed[fix.name] {
continue
}
+ if fix.disabled && !force[fix.name] {
+ continue
+ }
if fix.f(newFile) {
fixed = true
fmt.Fprintf(&fixlog, " %s", fix.name)
}
var netipv6zoneFix = fix{
- "netipv6zone",
- "2012-11-26",
- netipv6zone,
- `Adapt element key to IPAddr, UDPAddr or TCPAddr composite literals.
+ name: "netipv6zone",
+ date: "2012-11-26",
+ f: netipv6zone,
+ desc: `Adapt element key to IPAddr, UDPAddr or TCPAddr composite literals.
https://codereview.appspot.com/6849045/
`,
}
var printerconfigFix = fix{
- "printerconfig",
- "2012-12-11",
- printerconfig,
- `Add element keys to Config composite literals.`,
+ name: "printerconfig",
+ date: "2012-12-11",
+ f: printerconfig,
+ desc: `Add element keys to Config composite literals.`,
}
func printerconfig(f *ast.File) bool {