Skip to content

Bug: Can not show time.Duration #11

@soluty

Description

@soluty

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions