-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Use gofumpt if available, and enable gofumpt linter #3798
Conversation
380d7fc
to
a92c219
Compare
@crazy-max @vvoland ptal 😄 |
Makefile
Outdated
go list -f {{.Dir}} ./... | xargs gofmt -w -s -d | ||
fmt: ## run gofumpt (if present) or gofmt | ||
@if command -v gofumpt > /dev/null; then \ | ||
gofumpt -w -d . ; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gofumpt
automatically excludes vendor/
so no need to use go list
Hm... interesting; somehow my
|
Looks like the linter uses an explicit -lang, which (for go1.19) results in some additional formatting for octal values. Signed-off-by: Sebastiaan van Stijn <[email protected]>
gofumpt provides a supserset of gofmt / go fmt, but not every developer may have it installed, so for situations where it's not available, fall back to gofmt. As our code has been formatted with gofumpt already, in most cases contributions will follow those formatting rules, but in some cases there may be a difference, which would already be flagged by manual code review, but let's also enable the gofumpt linter. With this change, `make fmt` will use gofumpt is available; gofumpt has been added to the dev-container, so `make -f docker.Makefile fmt` will always use it. Signed-off-by: Sebastiaan van Stijn <[email protected]>
a92c219
to
c2f1671
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #3798 +/- ##
=======================================
Coverage 59.21% 59.21%
=======================================
Files 288 288
Lines 24605 24605
=======================================
Hits 14571 14571
Misses 9159 9159
Partials 875 875 |
go list -f {{.Dir}} ./... | xargs gofmt -w -s -d | ||
fmt: ## run gofumpt (if present) or gofmt | ||
@if command -v gofumpt > /dev/null; then \ | ||
gofumpt -w -d -lang=1.19 . ; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I need to add an explicit -lang=1.19
, otherwise it doesn't pick up the go version for which to format. Probably because we don't have a go.mod
@crazy-max ptal 🤗 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if opt-in.
Do we want a scheduled worklow to fix-up and open PR as semi-automation process?
Let me bring this one in 👍 |
gofumpt (https://github.com/mvdan/gofumpt) provides a supserset of gofmt / go fmt, but not every developer may have
it installed, so for situations where it's not available, fall back to gofmt.
As our code has been formatted with gofumpt already, in most cases contributions
will follow those formatting rules, but in some cases there may be a difference,
which would already be flagged by manual code review, but let's also enable the
gofumpt linter.
With this change,
make fmt
will use gofumpt is available; gofumpt has beenadded to the dev-container, so
make -f docker.Makefile fmt
will always use it.