Skip to content

Commit 84d28bf

Browse files
authored
Merge pull request #2088 from visualfc/format_echo
x/format: fmt.println => echo
2 parents 70e7ad0 + fb517b7 commit 84d28bf

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

x/format/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ n, err := fmt.Println("Hello world")
5151
will be converted into:
5252

5353
```go
54-
n, err := println("Hello world")
54+
n, err := echo("Hello world")
5555
```
5656

5757
Note:
@@ -62,7 +62,7 @@ Note:
6262
* Convert `fmt.Fprintln => fprintln`
6363
* Convert `fmt.Print` => `print`
6464
* Convert `fmt.Printf` => `printf`
65-
* Convert `fmt.Println` => `println`
65+
* Convert `fmt.Println` => `echo`
6666
* Convert `fmt.Sprint => sprint`
6767
* Convert `fmt.Sprintf => sprintf`
6868
* Convert `fmt.Sprintln => sprintln`
@@ -79,8 +79,8 @@ fmt.Println(fmt.Println("Hello world"))
7979
will be converted into:
8080

8181
```go
82-
println
83-
println println("Hello world")
82+
echo
83+
echo echo("Hello world")
8484
```
8585

8686
Note:

x/format/_testdata/collection/format.expect

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ func Map(vs []string, f func(string) string) []string {
8484
// Here we try out our various collection functions.
8585
var strs = []string{"peach", "apple", "pear", "plum"}
8686

87-
println Index(strs, "pear")
87+
echo Index(strs, "pear")
8888

89-
println Include(strs, "grape")
89+
echo Include(strs, "grape")
9090

91-
println Any(strs, v => strings.hasPrefix(v, "p"))
91+
echo Any(strs, v => strings.hasPrefix(v, "p"))
9292

93-
println All(strs, v => strings.hasPrefix(v, "p"))
93+
echo All(strs, v => strings.hasPrefix(v, "p"))
9494

95-
println Filter(strs, v => strings.contains(v, "e"))
95+
echo Filter(strs, v => strings.contains(v, "e"))
9696

9797
// The above examples all used anonymous functions,
9898
// but you can also use named functions of the correct
9999
// type.
100-
println Map(strs, strings.ToUpper)
100+
echo Map(strs, strings.ToUpper)

x/format/_testdata/syntax/format.expect

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ m := make(map[string]chan interface{})
77
for range arr[1:] {
88
foo:
99
*(p) = 1
10-
println f(arr...)
10+
echo f(arr...)
1111
m["a"] <- true
1212
}
1313
for i := 0; i < 10; i++ {

x/format/format.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func fmtToBuiltin(ctx *importCtx, sel *ast.Ident, ref *ast.Expr) bool {
4040
if ctx.pkgPath == "fmt" {
4141
for _, fns := range printFuncs {
4242
if fns[0] == sel.Name || fns[1] == sel.Name {
43-
*ref = &ast.Ident{NamePos: sel.NamePos, Name: fns[1]}
43+
name := fns[1]
44+
if name == "println" {
45+
name = "echo"
46+
}
47+
*ref = &ast.Ident{NamePos: sel.NamePos, Name: name}
4448
return true
4549
}
4650
}

x/format/gopstyle_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
`, `// this is main
4848
4949
// say hello
50-
println "Hello world"
50+
echo "Hello world"
5151
`)
5252
testFormat(t, "hello world 2", `package main
5353
@@ -64,7 +64,7 @@ func f() {
6464
`, `// this is main
6565
func main() {
6666
// say hello
67-
println "Hello world"
67+
echo "Hello world"
6868
}
6969
7070
func f() {
@@ -120,7 +120,7 @@ func f() {
120120
fmt.Println("hello")
121121
}
122122
`, `func f() {
123-
println "hello"
123+
echo "hello"
124124
}
125125
`)
126126
}
@@ -136,7 +136,7 @@ func f() {
136136
fmt.Println("hello")
137137
}
138138
`, `func f() {
139-
println "hello"
139+
echo "hello"
140140
}
141141
`)
142142
}
@@ -155,7 +155,7 @@ func f() {
155155
156156
func f() {
157157
errorf "%w", New("hello")
158-
println "hello"
158+
echo "hello"
159159
}
160160
`)
161161
}
@@ -178,7 +178,7 @@ func f() {
178178
179179
func f() {
180180
errorf "%w", errors.new("hello")
181-
println "hello"
181+
echo "hello"
182182
}
183183
`)
184184
}
@@ -197,7 +197,7 @@ func f() {
197197
198198
func f() {
199199
_ = errorf("%w", errors.new("hello"))
200-
println "hello"
200+
echo "hello"
201201
}
202202
`)
203203
}
@@ -220,7 +220,7 @@ func f() {
220220
221221
func f() {
222222
_ = errorf("%w", errors.new("hello"))
223-
println "hello"
223+
echo "hello"
224224
}
225225
`)
226226
}
@@ -238,7 +238,7 @@ func f() {
238238
239239
func f() {
240240
_ = fmt.Stringer
241-
println "hello"
241+
echo "hello"
242242
}
243243
`)
244244
}
@@ -256,7 +256,7 @@ func f() {
256256
257257
func f() {
258258
var _ fmt.Stringer
259-
println "hello"
259+
echo "hello"
260260
}
261261
`)
262262
}
@@ -280,7 +280,7 @@ func f() {
280280
fmt.Stringer
281281
fn func()
282282
}
283-
println "hello"
283+
echo "hello"
284284
}
285285
`)
286286
}
@@ -294,7 +294,7 @@ func f() {
294294
fmt1.Println("hello")
295295
}
296296
`, `func f() {
297-
println "hello"
297+
echo "hello"
298298
}
299299
`)
300300
}
@@ -312,8 +312,8 @@ func f() {
312312
fmt2.Println(2)
313313
}
314314
`, `func f() {
315-
println 1
316-
println 2
315+
echo 1
316+
echo 2
317317
}
318318
`)
319319
}
@@ -337,8 +337,8 @@ func f() {
337337
338338
func f() {
339339
var _ fmt.Stringer
340-
println 1
341-
println 2
340+
echo 1
341+
echo 2
342342
}
343343
`)
344344
}
@@ -426,7 +426,7 @@ func f() {
426426
_ = fmt
427427
}
428428
`, `func f() {
429-
println 1
429+
echo 1
430430
var fmt Foo
431431
_ = fmt
432432
}

0 commit comments

Comments
 (0)