Skip to content

Instantly share code, notes, and snippets.

@Akagi201
Last active September 28, 2020 03:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akagi201/b1a833389a299cbb00a2502b8bb9acc1 to your computer and use it in GitHub Desktop.
Save Akagi201/b1a833389a299cbb00a2502b8bb9acc1 to your computer and use it in GitHub Desktop.
C/C++ format tool based on clang-tidy and clang-format
BasedOnStyle: Google
TabWidth: 4
IndentWidth: 4
UseTab: ForIndentation
SpacesBeforeTrailingComments: 1
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
ColumnLimit: 79
MaxEmptyLinesToKeep: 2
#!/usr/bin/env bash
echo "clang-tidy starting "$*" ..."
sleep 1
TIDY="clang-tidy"
if [ -f /usr/local/opt/llvm/bin/clang-tidy ]; then
TIDY="/usr/local/opt/llvm/bin/clang-tidy"
fi
FORMAT="clang-format"
if [ -f /usr/local/bin/clang-format ]; then
FORMAT="/usr/local/bin/clang-format"
fi
$TIDY \
-fix \
-fix-errors \
-header-filter=.* \
--checks=readability-braces-around-statements,misc-macro-parentheses \
$* \
-- -I.
echo "clang-tidy finished!"
echo "clang-format starting "$*" ..."
sleep 1
$FORMAT -sort-includes -i $*
echo "clang-format finished!"
echo "iconv doc2unix starting "$*" ..."
sleep 1
for file in $*
do
iconv -f gbk -t utf8 "$file" >"$file.new"
mv -f "$file.new" "$file"
dos2unix "$file"
done
echo "iconv doc2unix finished!"
@Akagi201
Copy link
Author

Put these two files at the root of the project, and run ./format.sh xxx.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment