Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order slices of strings #34

Closed
domgreen opened this issue Aug 14, 2019 · 2 comments
Closed

Order slices of strings #34

domgreen opened this issue Aug 14, 2019 · 2 comments

Comments

@domgreen
Copy link

One thing that I often find in style guides is the desire to have lists of objects in order to help with readability.

Would be great if we could add a feature to order strings in slices when they are defined.

eg.

names := []string{
  "bob",
  "claire",
  "alice",
}

goes to:

names := []string{
  "alice",
  "bob",
  "claire",
}
@mvdan
Copy link
Owner

mvdan commented Aug 15, 2019

Thanks for the suggestion! Is your thinking that this would apply to all lists, or just some of them?

If this applies to all of them, I can imagine this meaning trouble. For example, what if a developer is keeping a particular order for some reason? Like:

days := []string{
    "Monday",
    "Tuesday",
    ...
}

We also don't want to add more flags beyond what gofmt has, so I don't know how we could make this apply to only some lists. Perhaps a comment, but then we get into ugly directives like //go:sorted.

@domgreen
Copy link
Author

Yeah, I'm not sure it can be applied everywhere tbh and don't like the idea of the comments. Will close the issue as I think it's something I'm going to just have to keep in the style guide. We do have a caveat on it that points out things like your days example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants