Skip to content

Commit a3a6503

Browse files
author
Yibing Liu
committed
add clang-format hook
1 parent 87931b4 commit a3a6503

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.clang-format

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is used by clang-format to autoformat paddle source code
2+
#
3+
# The clang-format is part of llvm toolchain.
4+
# It need to install llvm and clang to format source code style.
5+
#
6+
# The basic usage is,
7+
# clang-format -i -style=file PATH/TO/SOURCE/CODE
8+
#
9+
# The -style=file implicit use ".clang-format" file located in one of
10+
# parent directory.
11+
# The -i means inplace change.
12+
#
13+
# The document of clang-format is
14+
# http://clang.llvm.org/docs/ClangFormat.html
15+
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
16+
---
17+
Language: Cpp
18+
BasedOnStyle: Google
19+
IndentWidth: 2
20+
TabWidth: 2
21+
ContinuationIndentWidth: 4
22+
MaxEmptyLinesToKeep: 2
23+
AccessModifierOffset: -2 # The private/protected/public has no indent in class
24+
Standard: Cpp11
25+
AllowAllParametersOfDeclarationOnNextLine: true
26+
BinPackParameters: false
27+
BinPackArguments: false
28+
...
29+

.clang_format.hook

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# clang-format hook without version check
4+
5+
clang-format $@

.pre-commit-config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
files: \.md$
2626
- id: remove-tabs
2727
files: \.md$
28+
- repo: local
29+
hooks:
30+
- id: clang-format
31+
name: clang-format
32+
description: Format files with ClangFormat
33+
entry: bash .clang_format.hook -i
34+
language: system
35+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$
2836
- repo: local
2937
hooks:
3038
- id: convert-markdown-into-html

0 commit comments

Comments
 (0)