From a3a6503982694f5dc88d9dd85e14d732e2324ec4 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Fri, 8 Sep 2017 19:00:26 +0800 Subject: [PATCH] add clang-format hook --- .clang-format | 29 +++++++++++++++++++++++++++++ .clang_format.hook | 5 +++++ .pre-commit-config.yaml | 8 ++++++++ 3 files changed, 42 insertions(+) create mode 100644 .clang-format create mode 100755 .clang_format.hook diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..30863c27a8 --- /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 0000000000..9db4fe4550 --- /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 5ed1f4c4be..8ff36e098b 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