You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
time.Duration will cause ( missing ',' in argument list ) error
i wrote a hack and it can work well. change method gofumptFormatExpr
func gofumptFormatExpr(w io.Writer, fset *token.FileSet, expr ast.Expr, opt gofumpt.Options) error {
// First use go/format to convert the expression to Go syntax.
var tmp bytes.Buffer
if err := format.Node(&tmp, fset, expr); err != nil {
return err
}
rs := []rune(tmp.String())
var firstNum int
for i, v := range rs {
if v == '(' {
if rs[i+1] >= '0' && rs[i+1] <= '9' {
firstNum = i + 1
break
}
}
}
if firstNum > 0 {
rs0 := rs[:firstNum]
rs1 := rs[firstNum:]
var hasChar bool
for _, v := range rs1 {
if v < '0' || v > '9' {
hasChar = true
break
}
}
if hasChar {
rs1 = append([]rune{'_'}, rs1...)
}
rs = append(rs0, rs1...)
}
tmpString := string(formatCompositeLiterals(rs))
The text was updated successfully, but these errors were encountered:
Thanks for filing this, and sorry for the delayed follow-up. I think it would make sense to add support for time.Duration and time.Time natively. Happy to accept a PR for this if anyone has time and can add a few test cases alongside it.
time.Duration will cause ( missing ',' in argument list ) error
i wrote a hack and it can work well. change method gofumptFormatExpr
The text was updated successfully, but these errors were encountered: