diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6aab0240f56..129fb1c1723 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ ## Proposed Changes *Give a brief overview of your contribution here in a few sentences.* - + ## Related Work @@ -14,5 +14,6 @@ - [ ] I am submitting my contribution to the develop branch. - [ ] My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson). - [ ] My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/). +- [ ] I used the pre-commit hook to prevent dirty commits and used `pre-commit run --all` to format old commits. - [ ] I have added a test case that demonstrates my contribution, if necessary. - [ ] I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary. diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 00000000000..a0080f08981 --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,30 @@ +name: Code Style +on: + pull_request: + paths: + - "**.[ch]pp" + - "**.[ch]" + - "**.cfg" + - "**.py" + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + check-latest: true + - name: Install pre-commit + run: pip install pre-commit + - name: Run checks + run: pre-commit run -a -v + - name: Git status + if: always() + run: git status + - name: Full diff + if: always() + run: git diff diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..1e55bb83a10 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,62 @@ +repos: + # Official repo for the clang-format hook + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: "v15.0.7" + hooks: + - id: clang-format + exclude: | + (?x)^( + ^Common/include/CConfig.hpp| + ^Common/include/option_structure.hpp| + ^Common/src/CConfig.cpp| + ^SU2_CFD| + ^externals| + ^subprojects| + ^TestCases| + ^legacy + ) + types_or: [c++, c] + # black repo for python formatting + - repo: https://github.com/ambv/black + rev: 22.6.0 + hooks: + - id: black + exclude: | + (?x)^( + ^SU2_CFD| + ^externals| + ^subprojects| + ^TestCases| + ^legacy + ) + # Official repo for default hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.4.0" + hooks: + - id: mixed-line-ending + exclude: | + (?x)^( + ^SU2_CFD| + ^externals| + ^subprojects| + ^TestCases| + ^legacy + ) + - id: trailing-whitespace + exclude: | + (?x)^( + ^SU2_CFD| + ^externals| + ^subprojects| + ^TestCases| + ^legacy + ) + - id: end-of-file-fixer + exclude: | + (?x)^( + ^SU2_CFD| + ^externals| + ^subprojects| + ^TestCases| + ^legacy + )