Skip to content

Don't add pointer comments, or at least let the user disable them #56

@purpleidea

Description

@purpleidea

When printing with Sdump, we sometimes see these pointer comments:

// p0

and so on... This makes it more difficult to diff. Here's a workaround, but it would be nice to have an option to disable them:

pattern := regexp.MustCompile(`\ \/\/\ p[0-9]+$`) // the p0, p1 comments...
clean := func(s string) string {
	lines := []string{}
	for _, line := range strings.Split(s, "\n") {
		s := pattern.ReplaceAllLiteralString(line, "")
		lines = append(lines, s)
	}
	return strings.Join(lines, "\n")
}

lo1 := clean(lo.Sdump(exp))
lo2 := clean(lo.Sdump(ast))
if lo1 == lo2 { // simple diff
	return
}

I use this to diff two AST's in tests in https://github.com/purpleidea/mgmt/

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions