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

proposal: cmd/go: flag to run fieldalignment check #50826

Closed
frederikhors opened this issue Jan 26, 2022 · 4 comments
Closed

proposal: cmd/go: flag to run fieldalignment check #50826

frederikhors opened this issue Jan 26, 2022 · 4 comments

Comments

@frederikhors
Copy link

frederikhors commented Jan 26, 2022

I'm using golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment for field alignment and I'm having very bad moments reading my structs because I have this:

type Player struct {
  createdAt time.Time
  team      *Team
  pumID     *uint64
  Sponsorship
  description string
  teamID      uint64
  projectID   uint64
  categoryID  uint64
  authorID    uint64
  id          uint64
}

instead for example of this:

type Player struct {
  id        uint64
  createdAt time.Time

  description string

  authorID   uint64
  categoryID uint64
  projectID  uint64
  pumID      *uint64

  teamID uint64
  team   *Team

  Sponsorship
}

which is faster and clearer to read and understand for me.

PROPOSAL

Can we have some sort of build flag at compile time to apply fieldalignment on each struct in our project?

Something like:

go build --fieldalignment .

It would be very welcome and simple to realize I think.

Sorry if I wrote the proposal wrong.

@gopherbot gopherbot added this to the Proposal milestone Jan 26, 2022
@ianlancetaylor ianlancetaylor changed the title proposal: fieldalignment at compile time with a simple flag proposal: cmd/compile: flag to set field alignment Jan 26, 2022
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Jan 26, 2022
@ianlancetaylor ianlancetaylor changed the title proposal: cmd/compile: flag to set field alignment proposal: cmd/go: flag to run fieldalignment check Jan 26, 2022
@ianlancetaylor ianlancetaylor removed this from Incoming in Proposals (old) Jan 26, 2022
@ianlancetaylor
Copy link
Contributor

The Go tools separate analysis from compilation. We aren't going to change that now.

You can do this to run the test on a package:

go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
go vet -vettool=$(which fieldalignment) PACKAGE

You can list a bunch of packages as described at https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns.

Closing because we aren't going to make this kind of change.

@frederikhors
Copy link
Author

go vet -vettool=$(which fieldalignment)

Can I ask you what this does?

@frederikhors
Copy link
Author

I think my question is not answered. Can you please re-open this for a more properly discussion? Thanks @ianlancetaylor.

@ianlancetaylor
Copy link
Contributor

In general we don't use the issue tracker for questions or discussion. Questions get answered faster and more accurately on forums. See https://golang.org/wiki/Questions.

go vet is documented at https://pkg.go.dev/cmd/go#hdr-Report_likely_mistakes_in_packages which also documents the -vettool option. Hope this helps.

@golang golang locked and limited conversation to collaborators Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants