From bf5dd1513050a967fb2c7b7c777e7093198846dc Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Fri, 11 Jul 2025 11:47:30 -0700 Subject: [PATCH 1/3] Add commit hooks --- .clang-format | 27 +++++++++++++++++++++++++++ .gitignore | 3 +++ .pre-commit-config.yaml | 10 ++++++++++ test/CI/install_prehooks.sh | 16 ++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .clang-format create mode 100644 .pre-commit-config.yaml create mode 100755 test/CI/install_prehooks.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..cd614d8 --- /dev/null +++ b/.clang-format @@ -0,0 +1,27 @@ +--- +BasedOnStyle: LLVM + +--- +Language: Cpp +PointerAlignment: Left +AllowShortLoopsOnASingleLine: true + +# If parameters don't fit on one line format( +# arg1, arg2 +# ); +AlignAfterOpenBracket: BlockIndent + +# Try putting all constructor initializers +# on the next line if they don't fit, but, +# if they also don't fit on the next line, +# make them 1 per line +PackConstructorInitializers: NextLineOnly + +# Function calls and init lists try to fit +# args on same line, else all on next line, +# else one arg per line +BinPackArguments: false +AllowAllArgumentsOnNextLine: true + +# Don't reflow doxygen comment lines +CommentPragmas: '^\*? ?@' diff --git a/.gitignore b/.gitignore index 3e3dd51..549587c 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ CMakeCache.txt *Makefile *.cmake cmake_install.cmake + +# Pre-commit files +pre-commit-*.pyz diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..32e5336 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/crate-ci/typos + rev: v1.34.0 + hooks: + - id: typos + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v20.1.8 + hooks: + - id: clang-format + types_or: [c++, c] diff --git a/test/CI/install_prehooks.sh b/test/CI/install_prehooks.sh new file mode 100755 index 0000000..7062aa5 --- /dev/null +++ b/test/CI/install_prehooks.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +PRECOMMIT_VERSION="4.2.0" +PRECOMMIT_PYZ="pre-commit-${PRECOMMIT_VERSION}.pyz" +PRECOMMIT_URL="https://github.com/pre-commit/pre-commit/releases/download/v${PRECOMMIT_VERSION}/${PRECOMMIT_PYZ}" + +if ! [[ -f "$PRECOMMIT_PYZ" ]]; then + wget --no-verbose --show-progress "$PRECOMMIT_URL" + chmod u+x "$PRECOMMIT_PYZ" +fi +PRECOMMIT=${PWD}/$PRECOMMIT_PYZ + +#Go to git repo's root directory +cd $(git rev-parse --show-toplevel) + +$PRECOMMIT install From ab959f41f71a5011e0d52620d6b9e3b1ea60f3f9 Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Thu, 17 Jul 2025 13:01:05 -0700 Subject: [PATCH 2/3] Add linting workflow --- .github/workflows/linter.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/linter.yaml diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..ca4aec0 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -0,0 +1,23 @@ +name: Lint + +on: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v3 + + - name: Lint + uses: pre-commit/actions@v3.0.1 + + - name: Generate Suggestions + if: ${{ failure() }} + uses: reviewdog/action-suggester@v1.21.0 + with: + tool_name: Linter From 2534ecd80c624f7727b5723373c87ce75cbd0d4c Mon Sep 17 00:00:00 2001 From: Matthew Whitlock Date: Fri, 18 Jul 2025 07:03:07 -0700 Subject: [PATCH 3/3] Have linter check always succeed - linting strongly suggested but is admittedly sometimes silly --- .github/workflows/linter.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index ca4aec0..41a07b8 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -15,9 +15,9 @@ jobs: - name: Lint uses: pre-commit/actions@v3.0.1 + continue-on-error: true - name: Generate Suggestions - if: ${{ failure() }} uses: reviewdog/action-suggester@v1.21.0 with: tool_name: Linter