Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/format: non-idempotent format #11275

Closed
dvyukov opened this issue Jun 18, 2015 · 2 comments
Closed

go/format: non-idempotent format #11275

dvyukov opened this issue Jun 18, 2015 · 2 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 18, 2015

Repeated invocations of format.Source alter source:

package main

import (
    "bytes"
    "fmt"
    "go/format"
)

func main() {
    for _, data := range []string{"\n", "  "} {
        data1, err := format.Source([]byte(data))
        if err != nil {
            panic(err)
        }
        data2, err := format.Source(data1)
        if err != nil {
            panic(err)
        }
        if !bytes.Equal(data1, data2) {
            fmt.Printf("non-idempotent format: %q -> %q -> %q\n", data, data1, data2)
        }
    }
}
non-idempotent format: "\n" -> "\n\n" -> "\n\n\n\n"
non-idempotent format: "  " -> "\t  " -> "\t\t  "

go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64

@griesemer griesemer added this to the Go1.6 milestone Jun 18, 2015
@griesemer
Copy link
Contributor

May be an issue when using go/format to format partial code snippets, e.g. inside editors.

@gopherbot
Copy link

CL https://golang.org/cl/15154 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants