Skip to content

Commit 01b4f96

Browse files
authored
Merge pull request #2348 from MorganaFuture/morganaFuture/integrate-clang-tidy
Integrate clang-tidy for cpp files
2 parents d5ec427 + 1986b09 commit 01b4f96

File tree

4 files changed

+142
-2
lines changed

4 files changed

+142
-2
lines changed

.clang-tidy

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Checks: >
2+
clang-diagnostic-*,
3+
clang-diagnostic-error,
4+
clang-analyzer-*,
5+
clang-analyzer-core.*,
6+
clang-analyzer-cplusplus.*,
7+
clang-analyzer-deadcode.*,
8+
clang-analyzer-security.*,
9+
bugprone-*,
10+
cert-*,
11+
cppcoreguidelines-*,
12+
cppcoreguidelines-owning-memory,
13+
cppcoreguidelines-no-malloc,
14+
cppcoreguidelines-pro-bounds-array-to-pointer-decay,
15+
cppcoreguidelines-pro-bounds-constant-array-index,
16+
cppcoreguidelines-pro-bounds-pointer-arithmetic,
17+
cppcoreguidelines-pro-type-const-cast,
18+
cppcoreguidelines-pro-type-cstyle-cast,
19+
cppcoreguidelines-pro-type-reinterpret-cast,
20+
cppcoreguidelines-pro-type-union-access,
21+
cppcoreguidelines-slicing,
22+
google-build-using-namespace,
23+
google-explicit-constructor,
24+
google-readability-casting,
25+
google-runtime-int,
26+
google-runtime-operator,
27+
hicpp-exception-baseclass,
28+
hicpp-multiway-paths-covered,
29+
hicpp-no-malloc,
30+
hicpp-signed-bitwise,
31+
misc-*,
32+
modernize-*,
33+
mpi-*,
34+
performance-*,
35+
readability-*,
36+
-modernize-use-trailing-return-type,
37+
-readability-magic-numbers,
38+
-cppcoreguidelines-avoid-magic-numbers,
39+
-readability-identifier-length,
40+
-clang-diagnostic-error
41+
-misc-unused-using-decls,
42+
-misc-unused-parameters,
43+
-misc-include-cleaner
44+
45+
WarningsAsErrors: ''
46+
HeaderFilterRegex: '.*'
47+
FormatStyle: none
48+
49+
CheckOptions:
50+
- key: readability-identifier-naming.ClassCase
51+
value: CamelCase
52+
- key: readability-identifier-naming.VariableCase
53+
value: lower_case
54+
- key: readability-identifier-naming.PrivateMemberSuffix
55+
value: _
56+
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
57+
value: true
58+
- key: bugprone-dangling-handle.HandleClasses
59+
value: 'std::basic_string_view;std::span'
60+
- key: cert-dcl58-cpp.IgnoreMacros
61+
value: true
62+
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
63+
value: true
64+
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
65+
value: true
66+
- key: bugprone-argument-comment.StrictMode
67+
value: true
68+
- key: bugprone-easily-swappable-parameters.QualifiersMix
69+
value: true
70+
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
71+
value: true
72+
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
73+
value: true
74+
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
75+
value: true
76+
- key: bugprone-suspicious-enum-usage.StrictMode
77+
value: true
78+
- key: bugprone-suspicious-missing-comma.RatioThreshold
79+
value: 0.5
80+
- key: bugprone-suspicious-string-compare.StringCompareLikeFunctions
81+
value: 'strcmp;strncmp'
82+
- key: cppcoreguidelines-narrowing-conversions.PedanticMode
83+
value: true

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,8 @@ clean:
180180
$(MAKE) -C utils clean
181181
find . \( -name \*~ -o -name \*.orig -o -name \*.symvers \) \
182182
-exec rm -f {} \;
183+
184+
tidy:
185+
@echo "Running clang-tidy on C++ files..."
186+
@./scripts/run-clang-tidy.sh
187+
.PHONY: tidy

scripts/run-clang-tidy.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
CLICKHOUSE_INCLUDE="-I$(pwd)/utils/clickhouse-cpp"
4+
5+
detect_clang_tidy() {
6+
if command -v "clang-tidy" &> /dev/null; then
7+
echo "clang-tidy"
8+
return 0
9+
fi
10+
11+
for cmd in $(compgen -c | grep -E "^clang-tidy-[0-9]+$" | sort -r); do
12+
echo "$cmd"
13+
return 0
14+
done
15+
16+
echo ""
17+
return 1
18+
}
19+
20+
main() {
21+
CLANG_TIDY=$(detect_clang_tidy)
22+
23+
if [ -z "$CLANG_TIDY" ]; then
24+
echo "Error: clang-tidy not found. Please install clang-tidy."
25+
exit 1
26+
fi
27+
28+
echo "Using $CLANG_TIDY"
29+
30+
if [ -n "$1" ]; then
31+
CPP_FILES="$1"
32+
else
33+
CPP_FILES=$(find utils -name "*.cc" -o -name "*.cpp" -o -name "*.hh" -o -name "*.hpp" -o -name "*.h" \
34+
| grep -v "clickhouse-cpp" \
35+
| xargs grep -L "clickhouse/")
36+
fi
37+
38+
for file in $CPP_FILES; do
39+
echo "Checking $file..."
40+
$CLANG_TIDY "$file" --config-file=./.clang-tidy -- \
41+
-std=c++20 -stdlib=libc++
42+
done
43+
}
44+
45+
main "$@"

utils/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ all:
4242
$(MAKE) $(TARGET)
4343

4444
$(TARGET): $(OBJS)
45-
$(CXX) -o $@ $^ $(LDFLAGS)
45+
$(CXX) -O3 -s -Wall -Wextra -std=c++23 -o $@ $^ $(LDFLAGS)
4646

4747
%.o: %.cc
4848
$(CXX) $(CXXFLAGS) -c $< -o $@
@@ -63,4 +63,11 @@ clickhouse_install:
6363
clickhouse_clean:
6464
$(RM) -rf $(CLICKHOUSE_DIR)
6565

66-
.PHONY: all clean clickhouse clickhouse_install clickhouse_clean
66+
sanitize: $(OBJS)
67+
$(CXX) -O0 -g -Wall -Wextra -std=c++23 -fsanitize=address,undefined -fno-omit-frame-pointer -o $(TARGET) $^ $(LDFLAGS)
68+
69+
tfw_logger_sanitize:
70+
$(MAKE) clickhouse
71+
$(MAKE) sanitize
72+
73+
.PHONY: all clean clickhouse clickhouse_install clickhouse_clean sanitize tfw_logger_sanitize

0 commit comments

Comments
 (0)