mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-21 12:28:39 +00:00
util/codegen: format generated code with goimports, not gofmt
goimports is a superset of gofmt that also groups imports. (the goimports tool also adds/removes imports as needed, but that part is disabled here) Change-Id: Iacf0408dfd9497f4ed3da4fa50e165359ce38498 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
6bed781259
commit
373176ea54
@ -8,12 +8,13 @@
|
|||||||
package tailcfg
|
package tailcfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
"tailscale.com/types/dnstype"
|
"tailscale.com/types/dnstype"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/opt"
|
"tailscale.com/types/opt"
|
||||||
"tailscale.com/types/structs"
|
"tailscale.com/types/structs"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clone makes a deep copy of User.
|
// Clone makes a deep copy of User.
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/format"
|
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages"
|
"golang.org/x/tools/go/packages"
|
||||||
|
"golang.org/x/tools/imports"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WriteFormatted writes code to path.
|
// WriteFormatted writes code to path.
|
||||||
@ -29,7 +29,12 @@ import (
|
|||||||
// It is also easier to interpret gofmt errors
|
// It is also easier to interpret gofmt errors
|
||||||
// with an editor providing file and line numbers.
|
// with an editor providing file and line numbers.
|
||||||
func WriteFormatted(code []byte, path string) error {
|
func WriteFormatted(code []byte, path string) error {
|
||||||
out, fmterr := format.Source(code)
|
out, fmterr := imports.Process(path, code, &imports.Options{
|
||||||
|
Comments: true,
|
||||||
|
TabIndent: true,
|
||||||
|
TabWidth: 8,
|
||||||
|
FormatOnly: true, // fancy gofmt only
|
||||||
|
})
|
||||||
if fmterr != nil {
|
if fmterr != nil {
|
||||||
out = code
|
out = code
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user