diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..30863c27a8fdc1e9c94c8cd741bfc0d7031fc912 --- /dev/null +++ b/.clang-format @@ -0,0 +1,29 @@ +# This file is used by clang-format to autoformat paddle source code +# +# The clang-format is part of llvm toolchain. +# It need to install llvm and clang to format source code style. +# +# The basic usage is, +# clang-format -i -style=file PATH/TO/SOURCE/CODE +# +# The -style=file implicit use ".clang-format" file located in one of +# parent directory. +# The -i means inplace change. +# +# The document of clang-format is +# http://clang.llvm.org/docs/ClangFormat.html +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +BasedOnStyle: Google +IndentWidth: 2 +TabWidth: 2 +ContinuationIndentWidth: 4 +MaxEmptyLinesToKeep: 2 +AccessModifierOffset: -2 # The private/protected/public has no indent in class +Standard: Cpp11 +AllowAllParametersOfDeclarationOnNextLine: true +BinPackParameters: false +BinPackArguments: false +... + diff --git a/.clang_format.hook b/.clang_format.hook new file mode 100755 index 0000000000000000000000000000000000000000..9db4fe4550c44fdb60e48818841d99ba5a081f46 --- /dev/null +++ b/.clang_format.hook @@ -0,0 +1,5 @@ +#!/bin/bash + +# clang-format hook without version check + +clang-format $@ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ed1f4c4beb6eae16d319b25ec9959b61fe3fbc3..8ff36e098ba9ea25faec99ef2bf5ced768483975 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,14 @@ files: \.md$ - id: remove-tabs files: \.md$ +- repo: local + hooks: + - id: clang-format + name: clang-format + description: Format files with ClangFormat + entry: bash .clang_format.hook -i + language: system + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$ - repo: local hooks: - id: convert-markdown-into-html