This is an automated email from the ASF dual-hosted git repository.

xiaokang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git


The following commit(s) were added to refs/heads/main by this push:
     new eab0fa5b fix(C++): add .clang-tidy configuration and fix missing 
brackets (#851)
eab0fa5b is described below

commit eab0fa5b766b62163fa3890c5a732acdb3d55f9c
Author: 姚军 <[email protected]>
AuthorDate: Sat Feb 14 19:13:49 2026 +0800

    fix(C++): add .clang-tidy configuration and fix missing brackets (#851)
    
    Signed-off-by: 姚军 <[email protected]>
---
 .clang-tidy                                | 39 ++++++++++++++++++++++++++++++
 .pre-commit-config.yaml                    |  9 +++++++
 cpp/examples/bfs_father_example.cc         |  3 ++-
 cpp/examples/bfs_pull_example.cc           |  9 ++++---
 cpp/examples/bfs_push_example.cc           |  9 ++++---
 cpp/examples/bfs_stream_example.cc         |  6 +++--
 cpp/examples/pagerank_example.cc           |  3 ++-
 cpp/src/graphar/high-level/graph_reader.cc |  3 ++-
 cpp/src/graphar/label.cc                   |  6 ++---
 cpp/test/test_arrow_chunk_reader.cc        |  3 ++-
 cpp/test/test_builder.cc                   |  9 ++++---
 cpp/test/test_multi_property.cc            |  8 +++---
 12 files changed, 86 insertions(+), 21 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 00000000..33835249
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This configuration is adapted from 
arrow(https://github.com/apache/arrow/blob/main/.clang-tidy)
+# Licensed under the Apache License, Version 2.0.
+---
+Checks: |
+  clang-diagnostic-*,
+  clang-analyzer-*,
+  -clang-analyzer-alpha*,
+  google-*,
+  modernize-*,
+  -modernize-avoid-c-arrays,
+  -modernize-use-trailing-return-type,
+  -modernize-use-nodiscard,
+
+CheckOptions:
+  - key:             
google-readability-braces-around-statements.ShortStatementLines
+    value:           '1'
+  - key:             google-readability-function-size.StatementThreshold
+    value:           '800'
+  - key:             google-readability-namespace-comments.ShortNamespaceLines
+    value:           '10'
+  - key:             google-readability-namespace-comments.SpacesBeforeComments
+    value:           '2'
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d35fbce4..5774dd94 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -43,6 +43,15 @@ repos:
       types_or: [c++]
       args: [--style=file, --verbose]
       exclude: ^cpp/thirdparty/
+      
+  - repo: https://github.com/pocc/pre-commit-hooks
+    rev: v1.3.5
+    hooks:
+      - id: clang-tidy
+        stages:
+          - manual
+        args: ['--quiet', '--config-file=.clang-tidy']
+        types_or: [c++, c]
 
   - repo: https://github.com/compilerla/conventional-pre-commit
     rev: v3.0.0
diff --git a/cpp/examples/bfs_father_example.cc 
b/cpp/examples/bfs_father_example.cc
index b5d4adc3..f67ce8e5 100644
--- a/cpp/examples/bfs_father_example.cc
+++ b/cpp/examples/bfs_father_example.cc
@@ -68,8 +68,9 @@ int main(int argc, char* argv[]) {
       }
     }
     std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
-    if (count == 0)
+    if (count == 0) {
       break;
+    }
   }
   for (int i = 0; i < num_vertices; i++) {
     std::cout << i << ", distance: " << distance[i] << ", father: " << pre[i]
diff --git a/cpp/examples/bfs_pull_example.cc b/cpp/examples/bfs_pull_example.cc
index 530d5581..4f8e68b3 100644
--- a/cpp/examples/bfs_pull_example.cc
+++ b/cpp/examples/bfs_pull_example.cc
@@ -51,8 +51,9 @@ int main(int argc, char* argv[]) {
   // run bfs algorithm
   graphar::IdType root = 0;
   std::vector<int32_t> distance(num_vertices);
-  for (graphar::IdType i = 0; i < num_vertices; i++)
+  for (graphar::IdType i = 0; i < num_vertices; i++) {
     distance[i] = (i == root ? 0 : -1);
+  }
   auto it_begin = edges->begin(), it_end = edges->end();
   auto it = it_begin;
   for (int iter = 0;; iter++) {
@@ -60,8 +61,9 @@ int main(int argc, char* argv[]) {
     it.to_begin();
     for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
       if (distance[vid] == -1) {
-        if (!it.first_dst(it, vid))
+        if (!it.first_dst(it, vid)) {
           continue;
+        }
         // if (!it.first_dst(it_begin, vid)) continue;
         do {
           graphar::IdType src = it.source(), dst = it.destination();
@@ -74,8 +76,9 @@ int main(int argc, char* argv[]) {
       }
     }
     std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
-    if (count == 0)
+    if (count == 0) {
       break;
+    }
   }
   for (int i = 0; i < num_vertices; i++) {
     std::cout << i << ", distance: " << distance[i] << std::endl;
diff --git a/cpp/examples/bfs_push_example.cc b/cpp/examples/bfs_push_example.cc
index d6dbbc9c..0ba972cf 100644
--- a/cpp/examples/bfs_push_example.cc
+++ b/cpp/examples/bfs_push_example.cc
@@ -51,8 +51,9 @@ int main(int argc, char* argv[]) {
   // run bfs algorithm
   graphar::IdType root = 0;
   std::vector<int32_t> distance(num_vertices);
-  for (graphar::IdType i = 0; i < num_vertices; i++)
+  for (graphar::IdType i = 0; i < num_vertices; i++) {
     distance[i] = (i == root ? 0 : -1);
+  }
   auto it_begin = edges->begin(), it_end = edges->end();
   auto it = it_begin;
   for (int iter = 0;; iter++) {
@@ -60,8 +61,9 @@ int main(int argc, char* argv[]) {
     it.to_begin();
     for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
       if (distance[vid] == iter) {
-        if (!it.first_src(it, vid))
+        if (!it.first_src(it, vid)) {
           continue;
+        }
         // if (!it.first_src(it_begin, vid)) continue;
         do {
           graphar::IdType src = it.source(), dst = it.destination();
@@ -73,8 +75,9 @@ int main(int argc, char* argv[]) {
       }
     }
     std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
-    if (count == 0)
+    if (count == 0) {
       break;
+    }
   }
   for (int i = 0; i < num_vertices; i++) {
     std::cout << i << ", distance: " << distance[i] << std::endl;
diff --git a/cpp/examples/bfs_stream_example.cc 
b/cpp/examples/bfs_stream_example.cc
index 73abd219..bbf94087 100644
--- a/cpp/examples/bfs_stream_example.cc
+++ b/cpp/examples/bfs_stream_example.cc
@@ -51,8 +51,9 @@ int main(int argc, char* argv[]) {
   // run bfs algorithm
   graphar::IdType root = 0;
   std::vector<int32_t> distance(num_vertices);
-  for (graphar::IdType i = 0; i < num_vertices; i++)
+  for (graphar::IdType i = 0; i < num_vertices; i++) {
     distance[i] = (i == root ? 0 : -1);
+  }
   auto it_begin = edges->begin(), it_end = edges->end();
   for (int iter = 0;; iter++) {
     graphar::IdType count = 0;
@@ -64,8 +65,9 @@ int main(int argc, char* argv[]) {
       }
     }
     std::cout << "iter " << iter << ": " << count << " vertices." << std::endl;
-    if (count == 0)
+    if (count == 0) {
       break;
+    }
   }
   for (int i = 0; i < num_vertices; i++) {
     std::cout << i << ", distance: " << distance[i] << std::endl;
diff --git a/cpp/examples/pagerank_example.cc b/cpp/examples/pagerank_example.cc
index 9cd15f0f..2ea82d2a 100644
--- a/cpp/examples/pagerank_example.cc
+++ b/cpp/examples/pagerank_example.cc
@@ -74,8 +74,9 @@ int main(int argc, char* argv[]) {
     for (graphar::IdType i = 0; i < num_vertices; i++) {
       pr_next[i] = damping * pr_next[i] +
                    (1 - damping) * (1 / static_cast<double>(num_vertices));
-      if (out_degree[i] == 0)
+      if (out_degree[i] == 0) {
         pr_next[i] += damping * pr_curr[i];
+      }
       pr_curr[i] = pr_next[i];
       pr_next[i] = 0;
     }
diff --git a/cpp/src/graphar/high-level/graph_reader.cc 
b/cpp/src/graphar/high-level/graph_reader.cc
index 6b554565..7323e075 100644
--- a/cpp/src/graphar/high-level/graph_reader.cc
+++ b/cpp/src/graphar/high-level/graph_reader.cc
@@ -138,8 +138,9 @@ Result<std::vector<std::string>> VertexIter::label() 
noexcept {
 static inline bool IsValid(bool* state, int column_number) {
   for (int i = 0; i < column_number; ++i) {
     // AND case
-    if (!state[i])
+    if (!state[i]) {
       return false;
+    }
     // OR case
     // if (state[i]) return true;
   }
diff --git a/cpp/src/graphar/label.cc b/cpp/src/graphar/label.cc
index 7e1074ac..28778022 100644
--- a/cpp/src/graphar/label.cc
+++ b/cpp/src/graphar/label.cc
@@ -94,11 +94,11 @@ int read_parquet_file_and_get_valid_indices(
     }
     if (IsValid(state.get(), tested_label_num)) {
       count++;
-      if (query_type == QUERY_TYPE::INDEX)
-
+      if (query_type == QUERY_TYPE::INDEX) {
         indices->push_back(i + offset);
-      else if (query_type == QUERY_TYPE::BITMAP)
+      } else if (query_type == QUERY_TYPE::BITMAP) {
         SetBitmap(bitmap, i);
+      }
     }
   }
 
diff --git a/cpp/test/test_arrow_chunk_reader.cc 
b/cpp/test/test_arrow_chunk_reader.cc
index 2db69a81..b9aa8bcb 100644
--- a/cpp/test/test_arrow_chunk_reader.cc
+++ b/cpp/test/test_arrow_chunk_reader.cc
@@ -736,7 +736,8 @@ TEST_CASE_METHOD(GlobalFixture, "ArrowChunkReader") {
               idx++;
               sum += table->num_rows();
             } while (!reader->next_chunk().IsIndexError());
-            REQUIRE(table->num_columns() == (int) expected_cols.size());
+            REQUIRE(table->num_columns() ==
+                    static_cast<int>(expected_cols.size()));
 
             std::cout << "Total Nums: " << sum << "/"
                       << idx * edge_info->GetChunkSize() << '\n';
diff --git a/cpp/test/test_builder.cc b/cpp/test/test_builder.cc
index ab1d7364..404427c6 100644
--- a/cpp/test/test_builder.cc
+++ b/cpp/test/test_builder.cc
@@ -104,8 +104,9 @@ TEST_CASE_METHOD(GlobalFixture, "Test_vertices_builder") {
       getline(readstr, val, '|');
       if (i == 0) {
         int64_t x = 0;
-        for (size_t j = 0; j < val.length(); j++)
+        for (size_t j = 0; j < val.length(); j++) {
           x = x * 10 + val[j] - '0';
+        }
         v.AddProperty(names[i], x);
       } else {
         v.AddProperty(names[i], val);
@@ -198,12 +199,14 @@ TEST_CASE_METHOD(GlobalFixture, "test_edges_builder") {
     for (int i = 0; i < 3; i++) {
       getline(readstr, val, '|');
       if (i == 0) {
-        if (mapping.find(val) == mapping.end())
+        if (mapping.find(val) == mapping.end()) {
           mapping[val] = cnt++;
+        }
         s = mapping[val];
       } else if (i == 1) {
-        if (mapping.find(val) == mapping.end())
+        if (mapping.find(val) == mapping.end()) {
           mapping[val] = cnt++;
+        }
         d = mapping[val];
       } else {
         builder::Edge e(s, d);
diff --git a/cpp/test/test_multi_property.cc b/cpp/test/test_multi_property.cc
index 95714b72..f3f0fb74 100644
--- a/cpp/test/test_multi_property.cc
+++ b/cpp/test/test_multi_property.cc
@@ -65,7 +65,7 @@ namespace graphar {
 TEST_CASE_METHOD(GlobalFixture, "read multi-properties from csv file") {
   // read labels csv file as arrow table
   auto person_table = read_csv_to_table(test_data_dir + 
"/ldbc/person_0_0.csv");
-  auto seed = static_cast<unsigned int>(time(NULL));
+  auto seed = static_cast<unsigned int>(time(nullptr));
   int expected_row = rand_r(&seed) % person_table->num_rows();
   auto person_schema = person_table->schema();
   arrow::MemoryPool* pool = arrow::default_memory_pool();
@@ -121,8 +121,9 @@ TEST_CASE_METHOD(GlobalFixture, "read multi-properties from 
csv file") {
   std::string emails = "";
   for (int64_t i = start; i < end; ++i) {
     emails += values->GetString(i);
-    if (i < end - 1)
+    if (i < end - 1) {
       emails += ";";
+    }
   }
   std::cout << "random row: " << expected_row << std::endl;
   REQUIRE(expected_emails == emails);
@@ -156,8 +157,9 @@ TEST_CASE_METHOD(GlobalFixture, "read multi-properties from 
csv file") {
   end = email_result->length();
   for (int64_t i = 0; i < end; ++i) {
     emails += email_result->GetString(i);
-    if (i < end - 1)
+    if (i < end - 1) {
       emails += ";";
+    }
   }
   std::cout << emails << std::endl;
   REQUIRE(expected_emails == emails);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to