-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add betteralign linter #5417
Add betteralign linter #5417
Conversation
Hey, thank you for opening your first Pull Request ! |
In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements.
Pull Request Description
Linter
The Linter Tests Inside Golangci-lint
|
The main differences between betteralign and fieldalignment are related to CLI options, not to the core of the analysis. Those options are already handled by golangci-lint (ignore generated code, ignore tests, ignore directives, exclusions, etc.). So this is a duplicate. This linter is not designed to be used as a library, and it uses go1.24. |
While I don't mind having the PR closed (I really expected this, it's all fine and I understand), main difference is in decorated AST which means all comments locations/offsets are preserved when rewriting code. CLI is really irrelevant there, it's barebones singlechecker. In terms of why Go 1.24, |
The decorated AST is not compatible with the suggested fixes and so with the golangci-lint approach. Golangci-lint should be compiled with go1.23 and go1.24 and not only go1.24. |
You don't need to define the min go version to 1.24 to compile with go1.24: the min go version is related to the syntax used inside your code. The toolchain version is used to control the go version used to compile it as a standalone binary. The toolchain version is ignored when the module is used as a library but the min Go version is a hard requirement. |
@ldez My apologies, but it doesn't seem we are talking about the same thing. I am referring to how linters (for instance golangci-lint in the following example) don't work with Go 1.24 programs that have both go and toolchain set to 1.24 (for instance to force Abseil-variant of the map):
Same applies for other linters. |
golangci-lint works with go1.24 when compiled with go1.24, but not when compiled with go1.23, this is expected because golangci-lint can be used with the tool pattern (even if we discourage this usage) and so we should allow golangci-lint to be compiled with go1.23. The usage of the min Go version to force the compilation with go1.24 is an "abuse"/hack of the system. All our binaries are compiled with go1.24 and work with go1.24. |
betteralign is a tool to detect structs that would (theoretically) use less memory if their fields were sorted and optionally sort such fields. This is a fork of an official Go fieldalignment tool, but there are some notable changes in regards how it automatically skips over various generated files, test files, structs marked with
betteralign:ignore
comments, etc.The main feature is the ability to retain comment positions (field, doc, floating comments etc.) when rewriting files, although at least in Golangci-lint situation we can't have it enabled as it doesn't work through SuggestedFixes due to regular AST not retaining comment offsets/positions, so we dump decorated AST on our own, rewriting files directly.
Given how it primarily works through decorated AST, it might not be the best fit for golangci-lint, but I have been asked a few times to send a PR...