gofmt
- Formats
- Go
- In
ur.toml [format.go] style = "gofmt"- Its options
- https://pkg.go.dev/cmd/gofmt
Formatted
cart.go, as writtenpackage cart
// What a cart costs.
type Item struct { Name string; Price int; Quantity int }
func Subtotal(items []Item) int {
sum:=0
for _,item:=range items { sum+=item.Price*item.Quantity }
return sum
}
ur format --style gofmt cart.gopackage cart
// What a cart costs.
type Item struct {
Name string
Price int
Quantity int
}
func Subtotal(items []Item) int {
sum := 0
for _, item := range items {
sum += item.Price * item.Quantity
}
return sum
}
Defaults
The shared options, as gofmt sets them when nothing configures it. Its own names for them are read from its configuration files, but ur.toml sets them by the shared name only.
| Option | Default | gofmt calls it |
|---|---|---|
width | 100 | |
max-width | ||
indent.width | 8 | |
indent.style | ||
line-ending | "lf" | |
trailing-comma.add | "preserve" | |
trailing-comma.forces-break | false | |
quotes | "preserve" | |
target |
Its own options
Set in a table named for it, such as [format.gofmt], or in a language's table, as gofmt = { ... }.
| Option | Default | What it does |
|---|---|---|
s | false | Simplify the code where a shorter form means the same. Takes true or false. |
r | "" | Rewrite what matches a pattern before formatting, as pattern -> replacement. Takes a string. |