diff --git a/.clang-format b/.clang-format index b16e91a5..361e4b74 100644 --- a/.clang-format +++ b/.clang-format @@ -11,3 +11,4 @@ BreakInheritanceList: BeforeComma KeepEmptyLinesAtTheStartOfBlocks: false PointerAlignment: Left SpaceAfterTemplateKeyword: false +IndentRequires: false diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 00000000..f8fd1679 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,38 @@ +name: Clang-Format Workflow + +on: + push: + branches: '**' + pull_request: + +env: + LLVM_VERSION: 18 + +jobs: + format: + name: Check the formatting + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Pin to a specific version + run: | + $latestChocoVersion = (Resolve-ChocoPackageVersion -PackageName "llvm" -TargetVersion $env:LLVM_VERSION) + Install-ChocoPackage -PackageName llvm -ArgumentList '--allow-downgrade', '--version', $latestChocoVersion + + - name: Run clang-format + env: + RED4EXT_COMMIT_BEFORE: ${{ github.event.pull_request.base.sha || github.event.before }} + RED4EXT_COMMIT_AFTER: ${{ github.sha }} + run: | + git ` + -c core.autocrlf=false ` + -c core.eol=lf ` + -c color.ui=always ` + clang-format ` + --style file ` + --diff $env:RED4EXT_COMMIT_BEFORE $env:RED4EXT_COMMIT_AFTER ` diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..2042695e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +exclude: (^vendor/|(stdafx\.hpp|Resource\.(rc|hpp))$) +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.7 + hooks: + - id: clang-format diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c54a4e0f..47c6dd0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,6 +19,10 @@ The project is using [C++20](https://en.cppreference.com/w/cpp/20), any C++20 fe ### General * Use [EditorConfig](https://editorconfig.org/) and [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to style your code before pushing. + * Ideally, set up pre-commit hook using [pre-commit](https://pre-commit.com). + All that should be required to set it up is to have [Python 3.x](https://www.python.org/) with [pip](https://pypi.org/project/pip/) installed and run the following command inside of the cloned repository folder: `pip install pre-commit && pre-commit install` + * Note that first commit after setting up the hook will take longer as it has to download required packages. + * You don't have to run it every single time there is some update, hook is auto-updated after initial installation. * Use names that describe the purpose or intent of the object. Names should be self-explanatory and easily recognizable in the context. * Minimize the use of abbreviations that would likely be unknown to someone outside of the project. * Use `auto` whenever it is possible, if the intended type is the correct one (in case of primitive types).