1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
register(newWriterFix)
15
var newWriterFix = fix{
19
`Adapt bufio, gzip and zlib NewWriterXxx calls for whether they return errors.
21
Also rename gzip.Compressor and gzip.Decompressor to gzip.Writer and gzip.Reader.
23
http://codereview.appspot.com/5639057 and
24
http://codereview.appspot.com/5642054
28
func newWriter(f *ast.File) bool {
29
if !imports(f, "bufio") && !imports(f, "compress/gzip") && !imports(f, "compress/zlib") {
34
walk(f, func(n interface{}) {
35
switch n := n.(type) {
36
case *ast.SelectorExpr:
37
if isTopName(n.X, "gzip") {
38
switch n.Sel.String() {
40
n.Sel = &ast.Ident{Name: "Writer"}
43
n.Sel = &ast.Ident{Name: "Reader"}
46
} else if isTopName(n.X, "zlib") {
47
if n.Sel.String() == "NewWriterDict" {
48
n.Sel = &ast.Ident{Name: "NewWriterLevelDict"}
54
// Drop the ", _" in assignments of the form:
55
// w0, _ = gzip.NewWriter(w1)
56
if len(n.Lhs) != 2 || len(n.Rhs) != 1 {
59
i, ok := n.Lhs[1].(*ast.Ident)
63
if i.String() != "_" {
66
c, ok := n.Rhs[0].(*ast.CallExpr)
70
s, ok := c.Fun.(*ast.SelectorExpr)
76
case isTopName(s.X, "bufio") && (sel == "NewReaderSize" || sel == "NewWriterSize"):
78
case isTopName(s.X, "gzip") && sel == "NewWriter":
80
case isTopName(s.X, "zlib") && sel == "NewWriter":