Last active
November 5, 2022 14:46
-
-
Save dtoma/61468552bbc7c0114b2e700f9247a310 to your computer and use it in GitHub Desktop.
makefile rules to check style using 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
style: | |
@for src in $(SOURCES) ; do \ | |
echo "Formatting $$src..." ; \ | |
clang-format -i "$(SRC_DIR)/$$src" ; \ | |
clang-tidy -checks='-*,readability-identifier-naming' \ | |
-config="{CheckOptions: [ \ | |
{ key: readability-identifier-naming.NamespaceCase, value: lower_case },\ | |
{ key: readability-identifier-naming.ClassCase, value: CamelCase },\ | |
{ key: readability-identifier-naming.StructCase, value: CamelCase },\ | |
{ key: readability-identifier-naming.FunctionCase, value: camelBack },\ | |
{ key: readability-identifier-naming.VariableCase, value: lower_case },\ | |
{ key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }\ | |
]}" "$(SRC_DIR)/$$src" ; \ | |
done | |
@echo "Done" | |
check-style: | |
@for src in $(SOURCES) ; do \ | |
var=`clang-format "$(SRC_DIR)/$$src" | diff "$(SRC_DIR)/$$src" - | wc -l` ; \ | |
if [ $$var -ne 0 ] ; then \ | |
echo "$$src does not respect the coding style (diff: $$var lines)" ; \ | |
exit 1 ; \ | |
fi ; \ | |
done | |
@echo "Style check passed" | |
tidy: | |
@for src in $(SOURCES) ; do \ | |
echo "Running tidy on $$src..." ; \ | |
clang-tidy -checks="-*,modernize-use-auto,modernize-use-nullptr,\ | |
readability-else-after-return,readability-simplify-boolean-expr,\ | |
readability-redundant-member-init,modernize-use-default-member-init,\ | |
modernize-use-equals-default,modernize-use-equals-delete,\ | |
modernize-use-using,modernize-loop-convert,\ | |
cppcoreguidelines-no-malloc,misc-redundant-expression" \ | |
-header-filter=".*" \ | |
"$(SRC_DIR)/$$src" ; \ | |
done | |
@echo "Done" | |
.PHONY: style check-style tidy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment