Skip to content

Commit

Permalink
Merge pull request eclipse-uprotocol#209 from gregmedd/feature/linter…
Browse files Browse the repository at this point in the history
…/clang-format-fix-path-detect-version

Enhancing the clang-format linter script
  • Loading branch information
gregmedd authored Jul 16, 2024
2 parents eef86fe + e272326 commit e55bce5
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lint/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@

PROJECT_ROOT="$(realpath "$(dirname "$0")/../")"

echo "Running clang-format on all files in '$PROJECT_ROOT'"
if [ -n "$(which clang-format-12)" ]; then
# NOTE: Using clang-format-12 in CI system, too
FORMATTER=clang-format-12
elif [ -n "$(which clang-format)" ]; then
echo "Did not find clang-format-12. Trying clang-format. Results may not"
echo "match formatting in GitHub CI process."
FORMATTER=clang-format
else
echo "Could not find clang-format. Please make sure it is installed" 1>&2
exit 2
fi

echo "Running $FORMATTER on all files in '$PROJECT_ROOT'"
shopt -s globstar

pushd -n "$PROJECT_ROOT"
pushd "$PROJECT_ROOT" > /dev/null
for f in **/*.h **/*.cpp; do
echo
echo "Checking file '$f'"
# NOTE: Using clang-format-12 in CI system, too
clang-format-12 -i "$f"
if [[ ! ("$f" =~ "build/") ]]; then
echo
echo "Checking file '$f'"
$FORMATTER -i "$f"
fi
done
popd -n
popd > /dev/null

0 comments on commit e55bce5

Please sign in to comment.