From 990233336f8941a8f486deb22cfef09ebd570917 Mon Sep 17 00:00:00 2001 From: VasylBaran Date: Sun, 28 Jul 2024 18:51:37 +0300 Subject: [PATCH] Add an optional "---fix" argument to format-checking script --- .ci/clang-format.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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