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/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..41a07b8 --- /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 + continue-on-error: true + + - name: Generate Suggestions + uses: reviewdog/action-suggester@v1.21.0 + with: + tool_name: Linter 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