From d31022e33337306047fce309e263a4ef3fa70cee Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Wed, 9 Aug 2017 19:32:05 +0200 Subject: [PATCH 1/9] Add clang-format checks in Danger --- .clang-format | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 4 ++++ CMakeLists.txt | 2 +- Dangerfile | 2 ++ Gemfile | 1 + Gemfile.lock | 8 +++++++ hello_world.cpp | 9 ++++++-- vector.cpp | 13 +++++++++++ 8 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 .clang-format create mode 100644 vector.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..dd15387 --- /dev/null +++ b/.clang-format @@ -0,0 +1,59 @@ +AccessModifierOffset: -2 +AlignAfterOpenBracket: true +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 85 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +Language: Cpp +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Middle +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never diff --git a/.travis.yml b/.travis.yml index c1d7da4..9c5c402 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ dist: trusty compiler: clang os: linux ruby: 2.2.0 +addons: + apt: + packages: + - clang-format-3.5 before_script: - cmake --version - bundle install diff --git a/CMakeLists.txt b/CMakeLists.txt index f50d986..7c22aa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(hello_world CXX) -add_executable(hello_world hello_world.cpp) +add_executable(hello_world hello_world.cpp vector.cpp) enable_testing() diff --git a/Dangerfile b/Dangerfile index 5aa30ba..874816b 100644 --- a/Dangerfile +++ b/Dangerfile @@ -18,6 +18,8 @@ if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base} fail('Please rebase to get rid of the merge commits in this PR') end +code_style_validation.check + commit_lint.check lgtm.check_lgtm diff --git a/Gemfile b/Gemfile index 39ae4b9..95c2810 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,4 @@ gem "danger" gem "danger-commit_lint" gem "danger-lgtm" gem "danger-the_coding_love" +gem 'danger-code_style_validation', :git => 'https://github.com/robertodr/danger-code_style_validation.git' diff --git a/Gemfile.lock b/Gemfile.lock index 31ad2eb..c263818 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/robertodr/danger-code_style_validation.git + revision: 30f4c419369c53b2975f4b768e459a12e41811db + specs: + danger-code_style_validation (0.0.1) + danger-plugin-api (~> 1.0) + GEM remote: https://rubygems.org/ specs: @@ -58,6 +65,7 @@ PLATFORMS DEPENDENCIES danger + danger-code_style_validation! danger-commit_lint danger-lgtm danger-the_coding_love diff --git a/hello_world.cpp b/hello_world.cpp index 743be7c..1aaae3e 100644 --- a/hello_world.cpp +++ b/hello_world.cpp @@ -1,11 +1,16 @@ #include #include +#include + +std::vector myVector(); std::string message() { - return "Hello, Danger world!"; + return "Hello, Danger world!"; } int main() { std::cout << message() << std::endl; - return EXIT_SUCCESS; + + std::vector< int > v = myVector(); + return EXIT_SUCCESS; } diff --git a/vector.cpp b/vector.cpp new file mode 100644 index 0000000..0805daa --- /dev/null +++ b/vector.cpp @@ -0,0 +1,13 @@ +#include + +std::vector myVector() { +int arr[] = {16, 2, 77, 29}; +// Create a vector containing integers +std::vector v (arr, arr + sizeof(arr) /sizeof(arr[0]) ); + +// Add two more integers to vector +v.push_back(25); +v.push_back(13); + +return v; +} From c8f059d0dd9aa193940f97d88ddad6b6cb0d25fe Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 09:11:30 +0200 Subject: [PATCH 2/9] Add Travis job with GCC --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9c5c402..0da9820 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: cpp sudo: false dist: trusty -compiler: clang +compiler: + - clang + - gcc os: linux ruby: 2.2.0 addons: From 62cd2d4cd4489d47d9be413b9ed43d1266ec50ca Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 09:43:29 +0200 Subject: [PATCH 3/9] Execute Danger only once --- .travis.yml | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0da9820..b34b1bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,43 @@ language: cpp sudo: false dist: trusty -compiler: - - clang - - gcc -os: linux ruby: 2.2.0 +cache: bundler addons: apt: packages: - clang-format-3.5 +matrix: + include: + - os: linux + addons: + apt: + packages: + - g++ + env: + - CXX_COMPILER='g++' + - RUN_DANGER=false + - os: linux + addons: + apt: + packages: + - clang + - clang-format-3.5 + env: + - CXX_COMPILER='clang++' + - RUN_DANGER=true before_script: - cmake --version -- bundle install +- | + if [[ "${RUN_DANGER}" = true ]]; then + bundle install + fi script: -- bundle exec danger +- | + if [[ "${RUN_DANGER}" = true ]]; then + bundle exec danger + fi - cmake -H. -Bbuild - cd build -- make +- cmake --build . - ctest From 4266dae75130a398775dcb381adde14cf57d6c30 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 12:48:39 +0200 Subject: [PATCH 4/9] Update Gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index c263818..b334fa3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/robertodr/danger-code_style_validation.git - revision: 30f4c419369c53b2975f4b768e459a12e41811db + revision: 5ca556ea567ee0d95d3a3a0ec43de6fcaa06bcd5 specs: danger-code_style_validation (0.0.1) danger-plugin-api (~> 1.0) From b36ad197f97096a1b4e74b83df97d9714c3c4606 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 14:55:30 +0200 Subject: [PATCH 5/9] Update Gemfile.lock, remove one Danger plugin --- Dangerfile | 2 -- Gemfile.lock | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Dangerfile b/Dangerfile index 874816b..3f271d4 100644 --- a/Dangerfile +++ b/Dangerfile @@ -23,5 +23,3 @@ code_style_validation.check commit_lint.check lgtm.check_lgtm - -the_coding_love.random diff --git a/Gemfile.lock b/Gemfile.lock index b334fa3..7c2f464 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/robertodr/danger-code_style_validation.git - revision: 5ca556ea567ee0d95d3a3a0ec43de6fcaa06bcd5 + revision: 69305565a498705509835df630083b06463527e2 specs: danger-code_style_validation (0.0.1) danger-plugin-api (~> 1.0) From 9f37fefb92bbc278ed005ec375469299788a0bed Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 16:07:15 +0200 Subject: [PATCH 6/9] Update usage of code style validation plugin --- Dangerfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dangerfile b/Dangerfile index 3f271d4..c643d33 100644 --- a/Dangerfile +++ b/Dangerfile @@ -18,7 +18,7 @@ if git.commits.any? { |c| c.message =~ /^Merge branch '#{github.branch_for_base} fail('Please rebase to get rid of the merge commits in this PR') end -code_style_validation.check +code_style_validation.check file_extensions: ['.hpp', '.cpp', '.h', '.cc'] commit_lint.check diff --git a/Gemfile.lock b/Gemfile.lock index 7c2f464..1dad7c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/robertodr/danger-code_style_validation.git - revision: 69305565a498705509835df630083b06463527e2 + revision: af2b349f994bc7c391d22dc53bbef3fcfdf175b4 specs: danger-code_style_validation (0.0.1) danger-plugin-api (~> 1.0) From 8cfc4ae077dd6e4db3cc6fc7d44c0c59f88c0409 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Mon, 14 Aug 2017 20:08:45 +0200 Subject: [PATCH 7/9] Add default.nix, install clang-format-3.9 --- .travis.yml | 6 +++--- Gemfile.lock | 2 +- default.nix | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 default.nix diff --git a/.travis.yml b/.travis.yml index b34b1bd..84ab01d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: bundler addons: apt: packages: - - clang-format-3.5 + - clang-format-3.9 matrix: include: - os: linux @@ -22,7 +22,7 @@ matrix: apt: packages: - clang - - clang-format-3.5 + - clang-format-3.9 env: - CXX_COMPILER='clang++' - RUN_DANGER=true @@ -35,7 +35,7 @@ before_script: script: - | if [[ "${RUN_DANGER}" = true ]]; then - bundle exec danger + bundle exec danger fi - cmake -H. -Bbuild - cd build diff --git a/Gemfile.lock b/Gemfile.lock index 1dad7c0..ad782cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/robertodr/danger-code_style_validation.git - revision: af2b349f994bc7c391d22dc53bbef3fcfdf175b4 + revision: dfaae35836857bef0c3eb8499bbe7ef45c354e22 specs: danger-code_style_validation (0.0.1) danger-plugin-api (~> 1.0) diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c21deb6 --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +# default.nix +with import {}; +stdenv.mkDerivation { + name = "dev-environment"; # Probably put a more meaningful name here + buildInputs = [ bundler zlib ]; +} From 31d0f3015c66beb2b4ae4aa1d58afc06482171cc Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Mon, 14 Aug 2017 20:30:48 +0200 Subject: [PATCH 8/9] Add .clang-format --- .clang-format | 58 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/.clang-format b/.clang-format index dd15387..f0a182f 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,10 @@ +Language: Cpp AccessModifierOffset: -2 -AlignAfterOpenBracket: true +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false AlignEscapedNewlinesLeft: false -AlignOperands: true +AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false @@ -9,29 +12,56 @@ AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: false BinPackArguments: false BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -ColumnLimit: 85 -CommentPragmas: '^ IWYU pragma:' +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 85 +CommentPragmas: '^ IWYU pragma:' ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' IndentCaseLabels: true -IndentWidth: 2 +IndentWidth: 2 IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true -Language: Cpp +MacroBlockBegin: '' +MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBlockIndentWidth: 2 @@ -44,16 +74,18 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Middle +ReflowComments: true +SortIncludes: true SpaceAfterCStyleCast: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false +SpacesInAngles: false SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 -UseTab: Never +Standard: Cpp03 +TabWidth: 8 +UseTab: Never From 5010c2333ada2f39b817747cb0b4baf89e1e70a9 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Fri, 18 Aug 2017 15:15:15 +0200 Subject: [PATCH 9/9] Use offical 0.1.0 version of code style validation --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 95c2810..4a2b0d3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,4 @@ gem "danger" gem "danger-commit_lint" gem "danger-lgtm" gem "danger-the_coding_love" -gem 'danger-code_style_validation', :git => 'https://github.com/robertodr/danger-code_style_validation.git' +gem 'danger-code_style_validation', '0.1.0', :git => 'https://github.com/flix-tech/danger-code_style_validation.git' diff --git a/Gemfile.lock b/Gemfile.lock index ad782cb..172bf96 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT - remote: https://github.com/robertodr/danger-code_style_validation.git - revision: dfaae35836857bef0c3eb8499bbe7ef45c354e22 + remote: https://github.com/flix-tech/danger-code_style_validation.git + revision: 05925775fa1ba9cd3eda09437c8c7efba31ef59e specs: - danger-code_style_validation (0.0.1) + danger-code_style_validation (0.1.0) danger-plugin-api (~> 1.0) GEM @@ -38,7 +38,7 @@ GEM danger-the_coding_love (0.0.4) danger-plugin-api (~> 1.0) nokogiri - faraday (0.12.2) + faraday (0.13.0) multipart-post (>= 1.2, < 3) faraday-http-cache (1.3.1) faraday (~> 0.8) @@ -65,7 +65,7 @@ PLATFORMS DEPENDENCIES danger - danger-code_style_validation! + danger-code_style_validation (= 0.1.0)! danger-commit_lint danger-lgtm danger-the_coding_love