Skip to content
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

Switch from ClangFormat to Buf #36

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading