diff --git a/.github/check-c-formatting.sh b/.github/check-c-formatting.sh new file mode 100755 index 000000000..1047a1d53 --- /dev/null +++ b/.github/check-c-formatting.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +# I wanted to get the merge base using {{ github.base_ref }}, however this is only +# available for the event that opens the PR or edits it, not on pushes to the branch. +# Comparing to main should be an OK alternative, since it will - at worst - do more +# autoformatting than it otherwise would. + +[ -z "$1" ] && merge_base=main || merge_base="$1" + +git fetch origin $merge_base:refs/remotes/origin/$merge_base + +echo "$(clang-format --version)" +(git diff --name-only "origin/$merge_base") | while read filename; do + extension="${filename##*.}" + if [ "$extension" = "c" ] || [ "$extension" = "h" ]; then + clang-format -i -style=file "$filename" + fi +done diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e0d357537..78d2cdd40 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -9,9 +9,7 @@ jobs: - name: Check out openvas-scanner uses: actions/checkout@v4 - name: Formatting - run: | - clang-format -i -style=file {src,misc,nasl}/*.{c,h} - git diff --exit-code + run: sh .github/check-c-formatting.sh ${{ github.base_ref }} Rust: runs-on: ubuntu-latest defaults: diff --git a/src/utils.c b/src/utils.c index 1ce8afde8..742e0c700 100644 --- a/src/utils.c +++ b/src/utils.c @@ -280,8 +280,8 @@ write_script_stats (const char *buf, const char *path, int mode) pd = fopen (path, mode == 0 ? "a" : mode == 1 ? "r+" : "w"); if (pd == NULL) { - g_warning ("%s: Error opening FILE '%s' for script stats: %d - %s", __func__, - path, errno, strerror (errno)); + g_warning ("%s: Error opening FILE '%s' for script stats: %d - %s", + __func__, path, errno, strerror (errno)); return; }