Skip to content

Commit b2b8c34

Browse files
jelmeralexeagle
authored andcommitted
Add gofumpt as an alternative go formatter
gofumpt is a popular alternative formatter for Go that is compatible with gofmt but stricter.
1 parent e1d6a2d commit b2b8c34

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ It is also inspired by <https://github.com/github/super-linter>.
2929
| ---------------------- | --------------------- | ---------------- |
3030
| C / C++ | [clang-format] | ([#112]) |
3131
| CSS | [Prettier] | |
32-
| Go | [gofmt] | [golangci-lint] |
32+
| Go | [gofmt],[gofumpt] | [golangci-lint] |
3333
| HCL (Hashicorp Config) | [terraform] fmt | |
3434
| HTML | [Prettier] | |
3535
| JSON | [Prettier] | |
@@ -61,6 +61,7 @@ It is also inspired by <https://github.com/github/super-linter>.
6161
[buildifier]: https://github.com/keith/buildifier-prebuilt
6262
[prettier-plugin-sql]: https://github.com/un-ts/prettier
6363
[gofmt]: https://pkg.go.dev/cmd/gofmt
64+
[gofumpt]: https://github.com/mvdan/gofumpt
6465
[jsonnetfmt]: https://github.com/google/go-jsonnet
6566
[scalafmt]: https://scalameta.org/scalafmt
6667
[ruff]: https://docs.astral.sh/ruff/

example/WORKSPACE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pinned_maven_install()
201201
# Use whichever formatter binaries you need:
202202
load(
203203
"@aspect_rules_lint//format:repositories.bzl",
204+
"fetch_gofumpt",
204205
"fetch_java_format",
205206
"fetch_jsonnet",
206207
"fetch_ktfmt",
@@ -210,6 +211,8 @@ load(
210211
"fetch_terraform",
211212
)
212213

214+
fetch_gofumpt()
215+
213216
fetch_pmd()
214217

215218
fetch_jsonnet()

example/WORKSPACE.bzlmod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Needed until Bazel 7 allows MODULE.bazel to directly call repository rules
66
load(
77
"@aspect_rules_lint//format:repositories.bzl",
8+
"fetch_gofumpt",
89
"fetch_java_format",
910
"fetch_jsonnet",
1011
"fetch_ktfmt",
@@ -15,6 +16,8 @@ load(
1516
)
1617
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
1718

19+
fetch_gofumpt()
20+
1821
fetch_pmd()
1922

2023
fetch_jsonnet()

example/tools/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ alias(
8383
}),
8484
)
8585

86+
alias(
87+
name = "gofumpt",
88+
actual = select({
89+
"@io_bazel_rules_go//go/platform:darwin_amd64": "@com_github_mvdan_gofumpt_darwin_amd64//file",
90+
"@io_bazel_rules_go//go/platform:darwin_arm64": "@com_github_mvdan_gofumpt_darwin_arm64//file",
91+
"@io_bazel_rules_go//go/platform:linux_amd64": "@com_github_mvdan_gofumpt_linux_amd64//file",
92+
"@io_bazel_rules_go//go/platform:linux_arm64": "@com_github_mvdan_gofumpt_linux_arm64//file",
93+
}),
94+
)
8695
alias(
8796
name = "swiftformat",
8897
actual = select({
@@ -132,6 +141,7 @@ shellcheck_binary(name = "shellcheck")
132141
multi_formatter_binary(
133142
name = "format",
134143
cc = "@llvm_toolchain_llvm//:bin/clang-format",
144+
# Or ":gofumpt" if you want to use gofumpt instead of gofmt
135145
go = "@go_sdk//:bin/gofmt",
136146
java = ":java-format",
137147
javascript = ":prettier",

format/repositories.bzl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,48 @@ def fetch_swiftformat():
150150
sha256 = "978eaffdc3716bbc0859aecee0d83875cf3ab8d8725779448f0035309d9ad9f3",
151151
url = "https://github.com/nicklockwood/SwiftFormat/releases/download/0.49.17/swiftformat.zip",
152152
)
153+
154+
def fetch_gofumpt():
155+
http_file(
156+
name = "com_github_mvdan_gofumpt_linux_amd64",
157+
downloaded_file_path = "gofumpt",
158+
executable = True,
159+
sha256 = "759c6ab56bfbf62cafb35944aef1e0104a117e0aebfe44816fd79ef4b28521e4",
160+
urls = [
161+
"https://cdn.confidential.cloud/constellation/cas/sha256/759c6ab56bfbf62cafb35944aef1e0104a117e0aebfe44816fd79ef4b28521e4",
162+
"https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_linux_amd64",
163+
],
164+
)
165+
166+
http_file(
167+
name = "com_github_mvdan_gofumpt_linux_arm64",
168+
downloaded_file_path = "gofumpt",
169+
executable = True,
170+
sha256 = "fba20ffd06606c89a500e3cc836408a09e4767e2f117c97724237ae4ecadf82e",
171+
urls = [
172+
"https://cdn.confidential.cloud/constellation/cas/sha256/fba20ffd06606c89a500e3cc836408a09e4767e2f117c97724237ae4ecadf82e",
173+
"https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_linux_arm64",
174+
],
175+
)
176+
177+
http_file(
178+
name = "com_github_mvdan_gofumpt_darwin_amd64",
179+
downloaded_file_path = "gofumpt",
180+
executable = True,
181+
sha256 = "870f05a23541aad3d20d208a3ea17606169a240f608ac1cf987426198c14b2ed",
182+
urls = [
183+
"https://cdn.confidential.cloud/constellation/cas/sha256/870f05a23541aad3d20d208a3ea17606169a240f608ac1cf987426198c14b2ed",
184+
"https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_darwin_amd64",
185+
],
186+
)
187+
188+
http_file(
189+
name = "com_github_mvdan_gofumpt_darwin_arm64",
190+
downloaded_file_path = "gofumpt",
191+
executable = True,
192+
sha256 = "f2df95d5fad8498ad8eeb0be8abdb8bb8d05e8130b332cb69751dfd090fabac4",
193+
urls = [
194+
"https://cdn.confidential.cloud/constellation/cas/sha256/f2df95d5fad8498ad8eeb0be8abdb8bb8d05e8130b332cb69751dfd090fabac4",
195+
"https://github.com/mvdan/gofumpt/releases/download/v0.5.0/gofumpt_v0.5.0_darwin_arm64",
196+
],
197+
)

0 commit comments

Comments
 (0)