From bcb6f508b30c908bf379398a9d4a66342db06556 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 6 Sep 2024 14:33:22 +0900 Subject: [PATCH] GH-43979: [CI][C++][Dev] Add cpplint to pre-commit --- .pre-commit-config.yaml | 20 ++++++++++++++++++++ CPPLINT.cfg | 30 ++++++++++++++++++++++++++++++ cpp/CMakeLists.txt | 3 ++- cpp/build-support/run_cpplint.py | 20 -------------------- 4 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 CPPLINT.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf0bcde14622a..91017969eb502 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,6 +78,26 @@ repos: ?^cpp/src/generated/| ?^cpp/thirdparty/| ) + - repo: https://github.com/cpplint/cpplint + rev: 1.6.1 + hooks: + - id: cpplint + name: C++ Lint + args: + - "--verbose=2" + types_or: + - c++ + files: >- + ^cpp/ + exclude: >- + ( + ?\.grpc\.fb\.(cc|h)$| + ?\.pb\.(cc|h)$| + ?_generated.*\.(cc|h)$| + ?^cpp/src/arrow/vendored/| + ?^cpp/src/generated/| + ?^cpp/thirdparty/| + ) - repo: https://github.com/pre-commit/mirrors-clang-format rev: v14.0.6 hooks: diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 0000000000000..2f47b4dbf57b7 --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,30 @@ +# 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. + +filter = -build/c++11 +filter = -build/header_guard +filter = -build/include_order +filter = -build/include_what_you_use +filter = -readability/alt_tokens +# readability/casting is disabled as it aggressively warns about +# functions with names like "int32", so "int32(x)", where int32 is a +# function name, warns with +filter = -readability/casting +filter = -readability/todo +filter = -runtime/references +filter = -whitespace/comments +linelength = 90 diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 5ead9e4b063cd..423744c388471 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -301,7 +301,8 @@ add_custom_target(lint --cpplint_binary ${CPPLINT_BIN} ${COMMON_LINT_OPTIONS} - ${ARROW_LINT_QUIET}) + ${ARROW_LINT_QUIET} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) # # "make format" and "make check-format" targets diff --git a/cpp/build-support/run_cpplint.py b/cpp/build-support/run_cpplint.py index 76c0fe0aefaca..a81acf2eb2ff9 100755 --- a/cpp/build-support/run_cpplint.py +++ b/cpp/build-support/run_cpplint.py @@ -26,24 +26,6 @@ from functools import partial -# NOTE(wesm): -# -# * readability/casting is disabled as it aggressively warns about functions -# with names like "int32", so "int32(x)", where int32 is a function name, -# warns with -_filters = ''' --whitespace/comments --readability/casting --readability/todo --readability/alt_tokens --build/header_guard --build/c++11 --build/include_what_you_use --runtime/references --build/include_order -'''.split() - - def _get_chunk_key(filenames): # lists are not hashable so key on the first filename in a chunk return filenames[0] @@ -87,8 +69,6 @@ def _check_some_files(completed_processes, filenames): cmd = [ arguments.cpplint_binary, '--verbose=2', - '--linelength=90', - '--filter=' + ','.join(_filters) ] if (arguments.cpplint_binary.endswith('.py') and platform.system() == 'Windows'):