Skip to content

String formatting could be improved #2

@emidoots

Description

@emidoots

Today valast uses a dumb heuristic to determine if a string should be formatting as a Go "string literal" or `raw string literal`:

		if len(s) > 40 && strings.Contains(s, "\n") && !strings.Contains(s, "`") {
			return basicLit(vv, token.STRING, "string", "`"+s+"`", opt)
		}
		return basicLit(vv, token.STRING, "string", strconv.Quote(v.String()), opt)

No doubt there are cases where the formatting provided here will be less than optimal. Problematic cases include:

  • Very long single-line strings.
  • Multi-line strings with long lines.
  • Strings with lots of unicode where escape sequences (or not) may be more desirable.
  • ...

The goal of this issue is to find out how we can improve the default formatting to meet most use cases. It would then additionally be nice to have the ability for users of the package to provide a string for matter of their own, but we should do this after exhausting possibilities of improving the default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions