Skip to content

Commit

Permalink
GH-43979: [CI][C++][Dev] Add cpplint to pre-commit (#43982)
Browse files Browse the repository at this point in the history
### Rationale for this change

cpplint isn't integrated with pre-commit yet.

### What changes are included in this PR?

* Add cpplint configuration
* Share configuration with pre-commit and cpp/build-support/run_cpplint.py
* Add pre-commit entry

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* GitHub Issue: #43979

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
  • Loading branch information
kou authored Sep 6, 2024
1 parent 12dddfc commit 089ad78
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions cpp/build-support/run_cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 089ad78

Please sign in to comment.