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

cmd/go: add sort for go.mod after 'go mod tidy' #30897

guhan121 opened this issue Mar 18, 2019 · 2 comments


None yet
3 participants
Copy link

commented Mar 18, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.1 darwin/amd64

$go env

What did you do?

after run go mod tidy
the go.mod file is modified!
But if you diff it with last version by git tools,you can't see the change clearly。

i hope add a rule for sort lines in go.mod !

@ALTree ALTree added this to the Go1.13 milestone Mar 19, 2019

@ALTree ALTree added the modules label Mar 19, 2019

@ALTree ALTree changed the title add sort for go.mod after 'go mod tidy' cmd/go: add sort for go.mod after 'go mod tidy' Mar 19, 2019


This comment has been minimized.

Copy link

commented Mar 28, 2019

go commands that edit the go.mod file do preserve sort order within each block. Could you give a concrete example for which the result ends up unsorted?

sort.Slice(block.Line, func(i, j int) bool {
li := block.Line[i]
lj := block.Line[j]
for k := 0; k < len(li.Token) && k < len(lj.Token); k++ {
if li.Token[k] != lj.Token[k] {
return li.Token[k] < lj.Token[k]
return len(li.Token) < len(lj.Token)


This comment has been minimized.

Copy link

commented Apr 1, 2019

oh! sorry, because the go.mod in our project edit by developers not use go mod tidy,so it not sort.
i check the go.mod file. it is sorted!
As shown in the figure below:
On the left is developer submissions!
On the right is go mod tidy


@guhan121 guhan121 closed this Apr 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.