Last active
September 28, 2020 03:55
-
-
Save Akagi201/b1a833389a299cbb00a2502b8bb9acc1 to your computer and use it in GitHub Desktop.
C/C++ format tool based on clang-tidy and clang-format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BasedOnStyle: Google | |
TabWidth: 4 | |
IndentWidth: 4 | |
UseTab: ForIndentation | |
SpacesBeforeTrailingComments: 1 | |
AlignTrailingComments: true | |
AllowShortFunctionsOnASingleLine: false | |
AllowShortIfStatementsOnASingleLine: false | |
AllowShortLoopsOnASingleLine: false | |
ColumnLimit: 79 | |
MaxEmptyLinesToKeep: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put these two files at the root of the project, and run
./format.sh xxx.c