From 4b671e51cddf8c1ea0b06831594389f2f85e45b7 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Jan 2022 18:03:35 +0100 Subject: [PATCH 1/3] Add basic editorconfig file .editorconfig: Add basic editorconfig file that enforces tabs of indent size 4 on all C and C++ files and Unix-style line feeds and a final newline on all files. --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c2591ed --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# EditorConfig: https://editorconfig.org + +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{c,cc,cpp,h}] +indent_style = tab +indent_size = 4 From 2a8a31e1e2548cae2a82a1df64bce77aad57a2e1 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Jan 2022 18:06:50 +0100 Subject: [PATCH 2/3] Add a clang-format configuration .clang-format: Add a clang-format configuration file based on the WebKit style, that enforces a 120 char column length and tabs for indentation (of length four). --- .clang-format | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2c9b0e0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +BasedOnStyle: WebKit +AlignAfterOpenBracket: Align +ColumnLimit: 120 +CompactNamespaces: true +TabWidth: 4 +UseTab: ForIndentation From 45f82937bb689a686b864e9ea799f266e211ed18 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 4 Jan 2022 18:40:41 +0100 Subject: [PATCH 3/3] Add github workflow for checking code formatting .github/workflows/format.yml: Add github workflow for checking code formatting, which runs clang-format in a container and fails if there need to be changes to the formatting. --- .github/workflows/format.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..95c5b80 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,29 @@ +--- + +name: Check for correct formatting + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + check_formatting: + runs-on: ubuntu-latest + container: + image: archlinux:latest + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: pacman --noconfirm -Syu diffutils findutils clang + - name: Run clang-format on all C and C++ sources + run: | + cp -av ../jack-example-tools ../jack-example-tools.orig + find . -type f \( -iname "*.c" -or -iname "*.cc" -or -iname "*.cpp" -or -iname "*.h" \) -exec clang-format -i {} \; + - name: Check whether there are differences + run: | + if test -n "$(diff -ruN ../jack-example-tools.orig ../jack-example-tools)"; then + diff -ruN ../jack-example-tools.orig ../jack-example-tools + exit 1 + fi