Commit fd278ba1 authored by norvell's avatar norvell
Browse files

Merge branch 'ci/fix-check-format-to-ensure-one-newline-at-eof' into 'main'

[CI] Add function ensure-one-newline to scripts/check-format.sh since clang-13...

See merge request !1580
parents 29e1d626 2449a9f3
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -69,6 +69,16 @@ cl-format-apply() {
    ${CLANG_FORMAT} -i $1
}

ensure-one-newline()
{
    # first command adds a newline at the end of the file if there might be none
    # -> clang-format-13 does not add them and warnings e.g. on MacOS are triggered by them
    sed -i -e '$a\' $1
    # second command removes multiple newlines at the end of a file so that there is only one left
    # -> clang-format-13 does not do that, but complains about it
    sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $1
}

cl-format-check() {
    local I=$1
    local COLOR=$2
@@ -197,6 +207,7 @@ if [[ $NUMPROCS -lt 2 ]]; then
        RET=$?
        ((NUMFAILS+=RET))
        if [ $FORMAT ]; then
            ensure-one-newline $i
            cl-format-apply $i
        fi
    done
@@ -218,6 +229,7 @@ else
        fi
        ((NUMFAILS+=RET))
        if [ $FORMAT ]; then
            ensure-one-newline $i
            cl-format-apply $i
        fi ) &
        while [[ $(jobs -r -p | wc -l) -ge $NUMPROCS ]];do