From d968485341dbe8dcf9c8287833caaa151ab38daa Mon Sep 17 00:00:00 2001
From: Miguel Prada <miguel.prada@tecnalia.com>
Date: Mon, 2 Dec 2019 17:30:32 +0100
Subject: [PATCH] Add clang-format test for C++ code

---
 ...ab-industrial-ci-kinetic-no-rosinstall.yml | 11 ++++
 ...-industrial-ci-kinetic-with-rosinstall.yml | 11 ++++
 clang-format                                  | 66 +++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 clang-format

diff --git a/.gitlab-industrial-ci-kinetic-no-rosinstall.yml b/.gitlab-industrial-ci-kinetic-no-rosinstall.yml
index 866a9c7..78c2a4b 100644
--- a/.gitlab-industrial-ci-kinetic-no-rosinstall.yml
+++ b/.gitlab-industrial-ci-kinetic-no-rosinstall.yml
@@ -21,6 +21,7 @@ before_script:
     - apk add --update bash coreutils tar
     - git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci.git .ci_config -b legacy
     - docker login ${ARTIFACT_DOCKER_URL} -u ${ARTIFACT_CI_USER} -p ${ARTIFACT_CI_TOKEN}
+    - wget https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/13-add-clang-format-to-the-ci-tests/clang-format -O .clang-format
   script: .ci_config/gitlab.sh
   variables:
     ADDITIONAL_DEBS: curl
@@ -75,6 +76,16 @@ industrial_ci_kinetic_deploy:
   only:
     - tags
 
+clang_format:
+  extends: .industrial_ci
+  variables:
+    ROS_DISTRO: kinetic
+    CLANG_FORMAT_CHECK: file
+  except:
+    - tags
+    - melodic-devel
+  allow_failure: yes
+
 ##########################################################
 ## Simple check for basic Python syntax errors; this is much less thorough than
 ## other options like pylint, but much faster and less strict
diff --git a/.gitlab-industrial-ci-kinetic-with-rosinstall.yml b/.gitlab-industrial-ci-kinetic-with-rosinstall.yml
index 288675f..24555d5 100644
--- a/.gitlab-industrial-ci-kinetic-with-rosinstall.yml
+++ b/.gitlab-industrial-ci-kinetic-with-rosinstall.yml
@@ -21,6 +21,7 @@ before_script:
     - apk add --update bash coreutils tar
     - git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci.git .ci_config -b legacy
     - docker login ${ARTIFACT_DOCKER_URL} -u ${ARTIFACT_CI_USER} -p ${ARTIFACT_CI_TOKEN}
+    - wget https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/13-add-clang-format-to-the-ci-tests/clang-format -O .clang-format
   script: .ci_config/gitlab.sh
   variables:
     ADDITIONAL_DEBS: curl
@@ -77,6 +78,16 @@ industrial_ci_kinetic_deploy:
   only:
     - tags
 
+clang_format:
+  extends: .industrial_ci
+  variables:
+    ROS_DISTRO: kinetic
+    CLANG_FORMAT_CHECK: file
+  except:
+    - tags
+    - melodic-devel
+  allow_failure: yes
+
 ##########################################################
 ## Simple check for basic Python syntax errors; this is much less thorough than
 ## other options like pylint, but much faster and less strict
diff --git a/clang-format b/clang-format
new file mode 100644
index 0000000..56a30d3
--- /dev/null
+++ b/clang-format
@@ -0,0 +1,66 @@
+---
+BasedOnStyle: Google
+AccessModifierOffset: -2
+ConstructorInitializerIndentWidth: 2
+AlignEscapedNewlinesLeft: false
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakTemplateDeclarations: true
+AlwaysBreakBeforeMultilineStrings: false
+BreakBeforeBinaryOperators: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: true
+BinPackParameters: true
+ColumnLimit: 120
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+DerivePointerBinding: false
+PointerBindsToType: true
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 60
+PenaltyBreakString: 1
+PenaltyBreakFirstLessLess: 1000
+PenaltyExcessCharacter: 1000
+PenaltyReturnTypeOnItsOwnLine: 90
+SpacesBeforeTrailingComments: 2
+Cpp11BracedListStyle: false
+Standard: Auto
+IndentWidth: 2
+TabWidth: 2
+UseTab: Never
+IndentFunctionDeclarationAfterType: false
+SpacesInParentheses: false
+SpacesInAngles: false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterControlStatementKeyword: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+SortIncludes: false
+SpaceAfterCStyleCast: false
+
+# Configure each individual brace in BraceWrapping
+BreakBeforeBraces: Custom
+
+# Control of individual brace wrapping cases
+BraceWrapping: {
+    AfterClass: 'true'
+    AfterControlStatement: 'true'
+    AfterEnum : 'true'
+    AfterFunction : 'true'
+    AfterNamespace : 'true'
+    AfterStruct : 'true'
+    AfterUnion : 'true'
+    BeforeCatch : 'true'
+    BeforeElse : 'true'
+    IndentBraces : 'false'
+}
+...
-- 
GitLab