Import stanzas grouping


#1

Whilst I was waiting for a plane home from the last sprint I hacked together a quick MVP for the import stanza grouping that juju uses. This uses both gofmt/goimports for formatting, it’s by no means perfect, but does correctly do the following:

import (
        "fmt"
        "io"

        "github.com/aaa/bbb"
        "github.com/xxx/yyy"

        "github.com/juju/juju"
)

If people want to try it let me know stanzas… hopefully I’ll clean it up in the future to remove a lot of duplication between the formatting libraries.


#2

I definitely like the idea, it would be nice to configure my editor to support automatic imports and not end up grouping them differently than our standard style.

is it possible to have the ‘local prefixes’ automatically determined? Or should this just be a step during our normal ‘verify.sh’ ?


#3

So the idea is that this should just be another formatting tool inside your editor, so jujufmt or similar. And your IDE will do the work for you. I did look into verify.sh, but I’ve yet to think of a good way to do it nicely, but it should be doable with jujufmt.


#4

I’ve made an update to the stanza repo, to ignore generated files (mocks) and it works great for me.

https://youtu.be/EguALVNLwjM