diff --git a/.ci/clang-format.sh b/.ci/clang-format.sh index 0ccd4062..b9018f50 100755 --- a/.ci/clang-format.sh +++ b/.ci/clang-format.sh @@ -3,6 +3,11 @@ # SPDX-FileCopyrightText: 2023 Citra Emulator Project # SPDX-License-Identifier: GPL-2.0-or-later +fix=false +if [ "$1" == "--fix" ]; then + fix=true +fi + if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \ dist/*.svg dist/*.xml; then echo Trailing whitespace found, aborting @@ -25,11 +30,15 @@ fi set +x for f in $files_to_lint; do - d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true) - if ! [ -z "$d" ]; then - echo "!!! $f not compliant to coding style, here is the fix:" - echo "$d" - fail=1 + if [ "$fix" = true ]; then + $CLANG_FORMAT -i "$f" + else + d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true) + if ! [ -z "$d" ]; then + echo "!!! $f not compliant to coding style, here is the fix:" + echo "$d" + fail=1 + fi fi done