1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00
Satori/eng/formatting/format.sh
Alexander Köplinger 883ffc4d18
Fix format.sh script and remove dotnet-format tool from dotnet-tools.json (#94839)
We're no longer using the separate dotnet-format tool since it is integrated into the dotnet SDK now.

With the move to the SDK the options changed a bit so we now need to use the `whitespace` format command so we can continue using the `--folder` option: https://github.com/dotnet/format/issues/1385

To run not just whitespace but code style formatters as well we'd need a workspace context (i.e. pass the .csproj to dotnet format), but inferring that from just the changed file list is hard.
2023-11-16 15:38:39 +01:00

26 lines
812 B
Bash
Executable file

#!/bin/sh
LC_ALL=C
# Select files to format
NATIVE_FILES=$(git diff --cached --name-only --diff-filter=ACM "*.h" "*.hpp" "*.c" "*.cpp" "*.inl" | sed 's| |\\ |g')
MANAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" "*.vb" | sed 's| |\\ |g')
exec 1>&2
if [ -n "$NATIVE_FILES" ]; then
# Format all selected files
echo "$NATIVE_FILES" | cat | xargs | sed -e 's/ /,/g' | xargs "./artifacts/tools/clang-format" -style=file -i
# Add back the modified files to staging
echo "$NATIVE_FILES" | xargs git add
fi
if [ -n "$MANAGED_FILES" ]; then
# Format all selected files
echo "$MANAGED_FILES" | cat | xargs | sed -e 's/ /,/g' | dotnet format whitespace --include - --folder
# Add back the modified files to staging
echo "$MANAGED_FILES" | xargs git add
fi
exit 0