Created
February 3, 2021 15:50
-
-
Save heuristicus/94cb934fe7fa8b9f3cba940e533cf0ca to your computer and use it in GitHub Desktop.
Apply clang-tidy fixes to a codebase and make each fix an individual commit
This file contains hidden or 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
# This script runs clang-tidy on code to apply its checks for modernisation and readability, applying the fix for each | |
# check and creating a git commit for it. | |
# To set up conditions for this file | |
# 1. Compile your code with the flag -DCMAKE_COMPILE_COMMANDS=ON | |
# 2. go into the build directory for whatever package you are interested in - it will contain a compile_commands.json file. | |
# 3. Link compile_commands.json to wherever you have your git repostitory for the code with ln -s | |
# 4. Run this script in the git repository | |
# Get the checks we are going to apply to the code, skip the first line which is "enabled checks:" from the clang-tidy output | |
checks=(`clang-tidy -list-checks -checks="-*,readability*,modernization*" | tail -n +2`) | |
# Run each check on the code and commit the changes in a separate commit | |
for check in "${checks[@]}"; do | |
echo "Applying check $check" | |
# -checks="-*" removes all basic checks so that we only apply this specific check | |
run-clang-tidy -clang-apply-replacements-binary /usr/bin/clang-apply-replacements -checks="-*,${check}" -fix -quiet | |
echo "Creating commit..." | |
git add -u | |
git commit -m "Apply clang-tidy check $check" | |
echo "Done" | |
done | |
echo "Applied all checks and created commits." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment