Skip to content

"struct with X pointer bytes could be Y" linting errors for (what appears to be) aligned structs #302

@atc0005

Description

@atc0005

Summary

The changes from v0.3.19 and GH-287 resulted in numerous CI "failures" across projects that I maintain. Many of the complaints were solved by struct field reordering, but some issues persisted even after hours spent trying to align the fields per various guides. After spending far too long on this, I opened an upstream report with an example to reproduce the problem: golang/go#45541.

I learned that the issue had already been reported and responded to in golang/go#44877 (comment). That issue appears to have been closed without documentation changes, including how to disable that specific linting check.

From what I now understand, the fieldalignment linter bundles two diagnostics:

  • struct size
    • due to inefficient struct field alignment
  • pointer bytes
    • how many bytes of the object that the garbage collector (GC) has to potentially scan for pointers

For the second, the Go team member who maintained the now deprecated maligned linter indicated that it's not worth reporting to users by default; I've yet to find a way to selectively disable this diagnostic and golangci/golangci-lint#1825 was closed without resolution.

For now, I'm not sure whether it's worth reverting GH-287 or waiting to see what upstream and golangci-lint devs do to help mute the "pointer bytes" warnings. I'm learning towards reverting GH-287 for now.

References

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions