Skip to content

Commit

Permalink
Add gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
artnc committed May 17, 2024
1 parent a65c7a1 commit 5af42b1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ RUN apk add --no-cache --virtual .build-deps \
-o scalafmt \
&& rm /bin/coursier

# https://stackoverflow.com/a/59485924
COPY --from=golang:1.22.3-alpine3.18 /usr/local/go/bin/gofmt /gofmt

# Local files
COPY . .
RUN tsc \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This repo currently contains a single [pre-commit](https://pre-commit.com/) hook
- [isort](https://github.com/PyCQA/isort) v5.12.0 for Python 2
- [google-java-format](https://github.com/google/google-java-format) v1.18.1 for Java
- [ktfmt](https://github.com/facebookincubator/ktfmt) v0.46 for Kotlin
- [gofmt](https://pkg.go.dev/cmd/gofmt) v1.22.3 for Go
- [scalafmt](https://scalameta.org/scalafmt/) v3.7.16 for Scala
- [shfmt](https://github.com/mvdan/sh) v3.7.0 for Shell
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10138 for XML
Expand Down
6 changes: 6 additions & 0 deletions entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const enum HookName {
Autoflake = "autoflake",
Black = "Black",
ClangFormat = "ClangFormat",
Gofmt = "gofmt",
GoogleJavaFormat = "google-java-format",
Isort = "isort",
Ktfmt = "ktfmt",
Expand Down Expand Up @@ -182,6 +183,11 @@ const HOOKS: Record<HookName, LockableHook> = {
include: /\.proto$/,
runAfter: [HookName.Sed],
}),
[HookName.Gofmt]: createLockableHook({
action: sources => run("/gofmt", "-s", "-w", ...sources),
include: /\.go$/,
runAfter: [HookName.Sed],
}),
[HookName.GoogleJavaFormat]: createLockableHook({
action: sources =>
run("java", "-jar", "/google-java-format", "--replace", ...sources),
Expand Down
7 changes: 7 additions & 0 deletions test/after/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello world")
}
2 changes: 2 additions & 0 deletions test/before/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package main;import "fmt";func main(){
fmt.Println ("Hello world");}

0 comments on commit 5af42b1

Please sign in to comment.