shoenig / go-modtool

An opinionated tool for formatting and merging Go's go.mod and go.sum files.
Mozilla Public License 2.0
1 stars 0 forks source link

feature: sort lines inside `require` blocks #34

Open bkane-msft opened 1 month ago

bkane-msft commented 1 month ago

I'd find it handy to sort lines inside require blocks (it'll help me scan my dependencies easier).

Current:

require (
        go.bbkane.com/warg v0.0.23
        github.com/alessio/shellescape v1.4.2
        github.com/mitchellh/go-homedir v1.1.0
        github.com/sqlc-dev/sqlc v1.27.0
        github.com/stretchr/testify v1.9.0
        modernc.org/sqlite v1.33.0
        github.com/jedib0t/go-pretty/v6 v6.5.9
        golang.org/x/term v0.24.0
)

Proposed:

require (
        github.com/alessio/shellescape v1.4.2
        github.com/jedib0t/go-pretty/v6 v6.5.9
        github.com/mitchellh/go-homedir v1.1.0
        github.com/sqlc-dev/sqlc v1.27.0
        github.com/stretchr/testify v1.9.0
        go.bbkane.com/warg v0.0.23
        golang.org/x/term v0.24.0
        modernc.org/sqlite v1.33.0
)

Would you be open to a PR for this?

shoenig commented 1 month ago

Hi @bkane-msft! Yeah PR's are definitely welcome. For a moment I was confused, as sorting dependencies is a large part of the value of this tool, but I realized that only happens if you're using the go-modtool merge subcommand, which most projects probably have no use for. The sorting should definitely also take place in go-modtool fmt.

bkane-msft commented 1 month ago

Thanks @shoenig - I'll try to work on it in spare time. Until then this is easily worked around by running go mod tidy (whcih sorts lines within stanzas), after go-modtool fmt