Skip to content

Commit

Permalink
Switch from ClangFormat to Buf
Browse files Browse the repository at this point in the history
  • Loading branch information
artnc committed May 17, 2024
1 parent a65c7a1 commit ddeb56d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RUN apk add --no-cache --virtual .build-deps \
npm \
python3-dev \
&& apk add --no-cache \
clang-extra-tools \
libxslt \
nodejs \
openjdk17-jre-headless \
Expand All @@ -33,6 +32,9 @@ RUN apk add --no-cache --virtual .build-deps \
[email protected] \
[email protected] \
&& apk del .build-deps \
&& wget https://github.com/bufbuild/buf/releases/download/v1.32.0/buf-Linux-aarch64 -O buf \
&& chmod +x buf \
&& mkdir /.cache && chmod -R 777 /.cache \
&& wget https://github.com/google/google-java-format/releases/download/v1.18.1/google-java-format-1.18.1-all-deps.jar -O google-java-format \
&& wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.46/ktfmt-0.46-jar-with-dependencies.jar -O ktfmt \
&& wget https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_linux_amd64 -O shfmt \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This repo currently contains a single [pre-commit](https://pre-commit.com/) hook
- [shfmt](https://github.com/mvdan/sh) v3.7.0 for Shell
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10138 for XML
- [terraform fmt](https://github.com/hashicorp/terraform) v1.6.3 for Terraform
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v16.0.6 for Protobuf
- [Buf](https://github.com/bufbuild/buf) v1.32.0 for Protobuf
- [SVGO](https://github.com/svg/svgo) v3.0.3 for SVG
- Custom regex transformations (basically [sed](https://en.wikipedia.org/wiki/Sed)), for example:
- Trimming trailing whitespace and newlines
Expand Down
11 changes: 3 additions & 8 deletions entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const transformFile = (path: string, transform: (before: string) => string) =>
const enum HookName {
Autoflake = "autoflake",
Black = "Black",
ClangFormat = "ClangFormat",
Buf = "Buf",
GoogleJavaFormat = "google-java-format",
Isort = "isort",
Ktfmt = "ktfmt",
Expand Down Expand Up @@ -171,14 +171,9 @@ const HOOKS: Record<HookName, LockableHook> = {
include: /\.py$/,
runAfter: [HookName.Isort],
}),
[HookName.ClangFormat]: createLockableHook({
[HookName.Buf]: createLockableHook({
action: sources =>
run(
"clang-format",
"-i", // Edit files in-place
"--style=Google",
...sources,
),
run("/buf", "format", "-w", ...sources.flatMap(s => ["--path", s])),
include: /\.proto$/,
runAfter: [HookName.Sed],
}),
Expand Down

0 comments on commit ddeb56d

Please sign in to comment.