Skip to content

Commit 5bba90a

Browse files
committed
fix(C++): add .clang-tidy configuration and fix missing brackets
1 parent 02bd3fe commit 5bba90a

12 files changed

Lines changed: 86 additions & 21 deletions

.clang-tidy

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# This configuration is adapted from arrow(https://github.com/apache/arrow/blob/main/.clang-tidy)
19+
# Licensed under the Apache License, Version 2.0.
20+
---
21+
Checks: |
22+
clang-diagnostic-*,
23+
clang-analyzer-*,
24+
-clang-analyzer-alpha*,
25+
google-*,
26+
modernize-*,
27+
-modernize-avoid-c-arrays,
28+
-modernize-use-trailing-return-type,
29+
-modernize-use-nodiscard,
30+
31+
CheckOptions:
32+
- key: google-readability-braces-around-statements.ShortStatementLines
33+
value: '1'
34+
- key: google-readability-function-size.StatementThreshold
35+
value: '800'
36+
- key: google-readability-namespace-comments.ShortNamespaceLines
37+
value: '10'
38+
- key: google-readability-namespace-comments.SpacesBeforeComments
39+
value: '2'

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ repos:
4444
args: [--style=file, --verbose]
4545
exclude: ^cpp/thirdparty/
4646

47+
- repo: https://github.com/pocc/pre-commit-hooks
48+
rev: v1.3.5
49+
hooks:
50+
- id: clang-tidy
51+
stages:
52+
- manual
53+
args: ['--quiet', '--config-file=.clang-tidy']
54+
types_or: [c++, c]
55+
4756
- repo: local
4857
hooks:
4958
- id: spotless-java-info

cpp/examples/bfs_father_example.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ int main(int argc, char* argv[]) {
6868
}
6969
}
7070
std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
71-
if (count == 0)
71+
if (count == 0) {
7272
break;
73+
}
7374
}
7475
for (int i = 0; i < num_vertices; i++) {
7576
std::cout << i << ", distance: " << distance[i] << ", father: " << pre[i]

cpp/examples/bfs_pull_example.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ int main(int argc, char* argv[]) {
5151
// run bfs algorithm
5252
graphar::IdType root = 0;
5353
std::vector<int32_t> distance(num_vertices);
54-
for (graphar::IdType i = 0; i < num_vertices; i++)
54+
for (graphar::IdType i = 0; i < num_vertices; i++) {
5555
distance[i] = (i == root ? 0 : -1);
56+
}
5657
auto it_begin = edges->begin(), it_end = edges->end();
5758
auto it = it_begin;
5859
for (int iter = 0;; iter++) {
5960
graphar::IdType count = 0;
6061
it.to_begin();
6162
for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
6263
if (distance[vid] == -1) {
63-
if (!it.first_dst(it, vid))
64+
if (!it.first_dst(it, vid)) {
6465
continue;
66+
}
6567
// if (!it.first_dst(it_begin, vid)) continue;
6668
do {
6769
graphar::IdType src = it.source(), dst = it.destination();
@@ -74,8 +76,9 @@ int main(int argc, char* argv[]) {
7476
}
7577
}
7678
std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
77-
if (count == 0)
79+
if (count == 0) {
7880
break;
81+
}
7982
}
8083
for (int i = 0; i < num_vertices; i++) {
8184
std::cout << i << ", distance: " << distance[i] << std::endl;

cpp/examples/bfs_push_example.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ int main(int argc, char* argv[]) {
5151
// run bfs algorithm
5252
graphar::IdType root = 0;
5353
std::vector<int32_t> distance(num_vertices);
54-
for (graphar::IdType i = 0; i < num_vertices; i++)
54+
for (graphar::IdType i = 0; i < num_vertices; i++) {
5555
distance[i] = (i == root ? 0 : -1);
56+
}
5657
auto it_begin = edges->begin(), it_end = edges->end();
5758
auto it = it_begin;
5859
for (int iter = 0;; iter++) {
5960
graphar::IdType count = 0;
6061
it.to_begin();
6162
for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
6263
if (distance[vid] == iter) {
63-
if (!it.first_src(it, vid))
64+
if (!it.first_src(it, vid)) {
6465
continue;
66+
}
6567
// if (!it.first_src(it_begin, vid)) continue;
6668
do {
6769
graphar::IdType src = it.source(), dst = it.destination();
@@ -73,8 +75,9 @@ int main(int argc, char* argv[]) {
7375
}
7476
}
7577
std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
76-
if (count == 0)
78+
if (count == 0) {
7779
break;
80+
}
7881
}
7982
for (int i = 0; i < num_vertices; i++) {
8083
std::cout << i << ", distance: " << distance[i] << std::endl;

cpp/examples/bfs_stream_example.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ int main(int argc, char* argv[]) {
5151
// run bfs algorithm
5252
graphar::IdType root = 0;
5353
std::vector<int32_t> distance(num_vertices);
54-
for (graphar::IdType i = 0; i < num_vertices; i++)
54+
for (graphar::IdType i = 0; i < num_vertices; i++) {
5555
distance[i] = (i == root ? 0 : -1);
56+
}
5657
auto it_begin = edges->begin(), it_end = edges->end();
5758
for (int iter = 0;; iter++) {
5859
graphar::IdType count = 0;
@@ -64,8 +65,9 @@ int main(int argc, char* argv[]) {
6465
}
6566
}
6667
std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
67-
if (count == 0)
68+
if (count == 0) {
6869
break;
70+
}
6971
}
7072
for (int i = 0; i < num_vertices; i++) {
7173
std::cout << i << ", distance: " << distance[i] << std::endl;

cpp/examples/pagerank_example.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ int main(int argc, char* argv[]) {
7474
for (graphar::IdType i = 0; i < num_vertices; i++) {
7575
pr_next[i] = damping * pr_next[i] +
7676
(1 - damping) * (1 / static_cast<double>(num_vertices));
77-
if (out_degree[i] == 0)
77+
if (out_degree[i] == 0) {
7878
pr_next[i] += damping * pr_curr[i];
79+
}
7980
pr_curr[i] = pr_next[i];
8081
pr_next[i] = 0;
8182
}

cpp/src/graphar/high-level/graph_reader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ Result<std::vector<std::string>> VertexIter::label() noexcept {
138138
static inline bool IsValid(bool* state, int column_number) {
139139
for (int i = 0; i < column_number; ++i) {
140140
// AND case
141-
if (!state[i])
141+
if (!state[i]) {
142142
return false;
143+
}
143144
// OR case
144145
// if (state[i]) return true;
145146
}

cpp/src/graphar/label.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ int read_parquet_file_and_get_valid_indices(
9494
}
9595
if (IsValid(state.get(), tested_label_num)) {
9696
count++;
97-
if (query_type == QUERY_TYPE::INDEX)
98-
97+
if (query_type == QUERY_TYPE::INDEX) {
9998
indices->push_back(i + offset);
100-
else if (query_type == QUERY_TYPE::BITMAP)
99+
} else if (query_type == QUERY_TYPE::BITMAP) {
101100
SetBitmap(bitmap, i);
101+
}
102102
}
103103
}
104104

cpp/test/test_arrow_chunk_reader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ TEST_CASE_METHOD(GlobalFixture, "ArrowChunkReader") {
718718
idx++;
719719
sum += table->num_rows();
720720
} while (!reader->next_chunk().IsIndexError());
721-
REQUIRE(table->num_columns() == (int) expected_cols.size());
721+
REQUIRE(table->num_columns() ==
722+
static_cast<int>(expected_cols.size()));
722723

723724
std::cout << "Total Nums: " << sum << "/"
724725
<< idx * edge_info->GetChunkSize() << '\n';

0 commit comments

Comments
 (0)