From 9f331041ad9b920aef43d89afc5e7dfd9c2a5379 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 27 May 2021 07:20:45 -0700 Subject: [PATCH 1/2] Add pre-commit hook for buildifier My experience contributing here has been that nearly every PR snapshot required an extra push to run a buildifier command after a red CI run. This is easily automated. --- .bazelci/presubmit.yml | 3 ++- .pre-commit-config.yaml | 9 +++++++++ CONTRIBUTING.md | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index bd078b3302..3f170c6e70 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -35,4 +35,5 @@ tasks: - .bazelci/update_workspace_to_deps_heads.sh <<: *common -buildifier: latest +buildifier: + version: 4.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..fa3c57b57b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +# See CONTRIBUTING.md for instructions. +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/keith/pre-commit-buildifier + rev: 4.0.1.1 + hooks: + - id: buildifier + - id: buildifier-lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d10b8db5d..1a6ffbe744 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,19 @@ We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. +## Formatting + +Starlark files should be formatted by buildifier. +We suggest using a pre-commit hook to automate this. +First [install pre-commit](https://pre-commit.com/#installation), +then run + +```shell +pre-commit install +``` + +Otherwise the Buildkite CI will yell at you about formatting/linting violations. + ## File or claim an issue Please let us know what you're working on if you want to change or add to the From 5c4a8e32758ffba0bb5227e1e3dc21fec3b5bc1f Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 2 Jun 2021 12:51:25 -0700 Subject: [PATCH 2/2] Restore presubmit.yml --- .bazelci/presubmit.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 3f170c6e70..bd078b3302 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -35,5 +35,4 @@ tasks: - .bazelci/update_workspace_to_deps_heads.sh <<: *common -buildifier: - version: 4.0.1 +buildifier: latest