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: Inconsistent indentation in struct literal with long field names #17705

Closed
calmh opened this issue Oct 31, 2016 · 4 comments
Closed

cmd/gofmt: Inconsistent indentation in struct literal with long field names #17705

calmh opened this issue Oct 31, 2016 · 4 comments

Comments

@calmh
Copy link
Contributor

@calmh calmh commented Oct 31, 2016

Go 1.7.3.

https://play.golang.org/p/R2C1ULJxFq

When the difference in length between two sucessive struct fields exceeds 15 characters, indentation is restarted. Is this intentional? That is, this declaration:

	foo := T{
		ID:                    42,
		ShortID:               40,
		ProgressTickIntervalS: 10,
		Cancel:                make(chan struct{}),
	}

which looks fine, becomes this when the ShortID field is removed:

	bar := T{
		ID: 42,
		ProgressTickIntervalS: 10,
		Cancel:                make(chan struct{}),
	}

This is unexpected to me, I would expect the 42 to remain aligned with the 10.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 31, 2016

This is a feature.

@bradfitz bradfitz closed this Oct 31, 2016
@calmh
Copy link
Contributor Author

@calmh calmh commented Oct 31, 2016

It's a misfeature when it causes this kind of diff:

        fchan, err := scanner.Walk(scanner.Config{
-               Folder:                folderCfg.ID,
-               Dir:                   folderCfg.Path(),
-               Subs:                  subDirs,
-               Matcher:               ignores,
-               BlockSize:             protocol.BlockSize,
-               TempNamer:             defTempNamer,
-               TempLifetime:          time.Duration(m.cfg.Options().KeepTemporariesH) * time.Hour,
-               CurrentFiler:          cFiler{m, folder},
-               Lstater:               mtimefs,
-               IgnorePerms:           folderCfg.IgnorePerms,
-               AutoNormalize:         folderCfg.AutoNormalize,
-               Hashers:               m.numHashers(folder),
-               ShortID:               m.shortID,
+               Folder:        folderCfg.ID,
+               Dir:           folderCfg.Path(),
+               Subs:          subDirs,
+               Matcher:       ignores,
+               BlockSize:     protocol.BlockSize,
+               TempNamer:     defTempNamer,
+               TempLifetime:  time.Duration(m.cfg.Options().KeepTemporariesH) * time.Hour,
+               CurrentFiler:  cFiler{m, folder},
+               Lstater:       mtimefs,
+               IgnorePerms:   folderCfg.IgnorePerms,
+               AutoNormalize: folderCfg.AutoNormalize,
+               Hashers:       m.numHashers(folder),
+               ID:            m.id,
                ProgressTickIntervalS: folderCfg.ScanProgressIntervalS,
                Cancel:                cancel,
        })
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 31, 2016

In any case, it's intentional.

Code formatters often generates diffs of unrelated code. C'est la vie.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 31, 2016

See also #16170 for an explanation (you need to read among the comments. The ratio between different entries matters).

@golang golang locked and limited conversation to collaborators Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.