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/gofmt: align renamed imports #32189

Open
dsnet opened this issue May 22, 2019 · 4 comments
Open

cmd/gofmt: align renamed imports #32189

dsnet opened this issue May 22, 2019 · 4 comments
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented May 22, 2019

Currently, my import block looks something like:

import (
	"bytes"
	"math"
	"reflect"
	"testing"

	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
	"google.golang.org/protobuf/internal/encoding/pack"
	pimpl "google.golang.org/protobuf/internal/impl"
	"google.golang.org/protobuf/internal/pragma"
	ptype "google.golang.org/protobuf/internal/prototype"
	"google.golang.org/protobuf/internal/scalar"
	pref "google.golang.org/protobuf/reflect/protoreflect"
	preg "google.golang.org/protobuf/reflect/protoregistry"
	piface "google.golang.org/protobuf/runtime/protoiface"

	proto2_20180125 "google.golang.org/protobuf/internal/testprotos/legacy/proto2.v1.0.0-20180125-92554152"
)

Most of the import paths have a shared prefix, but the lack of aligning makes this hard to see. Preferably, gofmt would align the imports like:

import (
	"bytes"
	"math"
	"reflect"
	"testing"

	       "github.com/google/go-cmp/cmp"
	       "github.com/google/go-cmp/cmp/cmpopts"
	       "google.golang.org/protobuf/internal/encoding/pack"
	pimpl  "google.golang.org/protobuf/internal/impl"
	       "google.golang.org/protobuf/internal/pragma"
	ptype  "google.golang.org/protobuf/internal/prototype"
	       "google.golang.org/protobuf/internal/scalar"
	pref   "google.golang.org/protobuf/reflect/protoreflect"
	preg   "google.golang.org/protobuf/reflect/protoregistry"
	piface "google.golang.org/protobuf/runtime/protoiface"

	proto2_20180125 "google.golang.org/protobuf/internal/testprotos/legacy/proto2.v1.0.0-20180125-92554152"
)
@bcmills
Copy link
Contributor

bcmills commented May 22, 2019

CC @griesemer

@bcmills bcmills added this to the Proposal milestone May 22, 2019
@bcmills bcmills added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal labels May 22, 2019
@griesemer griesemer self-assigned this May 22, 2019
@griesemer griesemer modified the milestones: Proposal, Go1.14 May 22, 2019
@griesemer
Copy link
Contributor

I'm ok with this if we decide to make this change. Marking for Go 1.14, pending decision.

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@dsnet
Copy link
Member Author

dsnet commented Apr 13, 2020

I'm doing some LSCs (large-scale changes) and I'm observing that a frequent cause of merge conflicts is due to alignment changing many more lines than the change was strictly about (I commonly run into this issue with Go map literals and trailing comments).

I should note that while alignment brings a positive benefit to readability, it brings the detriment of higher probability of a merge conflict when two authors modify the same file and add/remove some imports.

@myitcv
Copy link
Member

myitcv commented Apr 13, 2020

Just noting in passing that this was discussed in #tools on Slack:

https://gophers.slack.com/archives/C0VPK4Z5E/p1580142385130500

@josharian noted in his response that he had previously looked at this in the form of https://github.com/whatsnu/semdiffstat.

I never got round to looking at how/whether it was possible to use something like semdiffstat during a merge/rebase (which was my main use case, much like yours).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants