Permalink
Browse files

Add clang-format (#1701)

* Checkout old .clang-format and build-linux.sh

* Remove now-duplicate clang-format installation

* Factor CI check into utl/ script

* Run ./utl/clang-format fix using old configuration

* Reformat with AllowShortFunctionsOnASingleLine: All

* Re-checkout from master and re-run utl/clang-format

includes were mysteriously sorted somewhere along the way?

* Use = for string equality in utl/clang-format

* Set BinPackParameters to true

* Add commentary to utl/clang-format script
  • Loading branch information...
palmerlao authored and JohnLangford committed Feb 5, 2019
1 parent 2f6acde commit d0c9042ca1057c858c8158d0d4b7335a12abd491
Showing with 11,229 additions and 9,887 deletions.
  1. +90 −0 .clang-format
  2. +6 −0 build-linux.sh
  3. +22 −0 utl/clang-format
  4. +84 −93 vowpalwabbit/OjaNewton.cc
  5. +18 −16 vowpalwabbit/accumulate.cc
  6. +1 −1 vowpalwabbit/accumulate.h
  7. +1 −2 vowpalwabbit/action_score.cc
  8. +37 −43 vowpalwabbit/action_score.h
  9. +31 −32 vowpalwabbit/active.cc
  10. +3 −2 vowpalwabbit/active.h
  11. +69 −61 vowpalwabbit/active_cover.cc
  12. +42 −43 vowpalwabbit/active_interactor.cc
  13. +91 −78 vowpalwabbit/allreduce.h
  14. +57 −53 vowpalwabbit/allreduce_sockets.cc
  15. +2 −2 vowpalwabbit/allreduce_threads.cc
  16. +159 −129 vowpalwabbit/array_parameters.h
  17. +32 −36 vowpalwabbit/array_parameters_dense.h
  18. +47 −57 vowpalwabbit/audit_regressor.cc
  19. +4 −5 vowpalwabbit/autolink.cc
  20. +21 −16 vowpalwabbit/baseline.cc
  21. +1 −1 vowpalwabbit/baseline.h
  22. +156 −113 vowpalwabbit/beam.h
  23. +42 −33 vowpalwabbit/best_constant.cc
  24. +10 −6 vowpalwabbit/best_constant.h
  25. +292 −286 vowpalwabbit/bfgs.cc
  26. +5 −6 vowpalwabbit/binary.cc
  27. +86 −68 vowpalwabbit/boosting.cc
  28. +51 −52 vowpalwabbit/bs.cc
  29. +44 −23 vowpalwabbit/bs.h
  30. +26 −25 vowpalwabbit/cache.cc
  31. +2 −3 vowpalwabbit/cache.h
  32. +63 −74 vowpalwabbit/cb.cc
  33. +19 −13 vowpalwabbit/cb.h
  34. +72 −74 vowpalwabbit/cb_adf.cc
  35. +1 −1 vowpalwabbit/cb_adf.h
  36. +24 −26 vowpalwabbit/cb_algs.cc
  37. +16 −11 vowpalwabbit/cb_algs.h
  38. +65 −70 vowpalwabbit/cb_explore.cc
  39. +3 −1 vowpalwabbit/cb_explore.h
  40. +188 −201 vowpalwabbit/cb_explore_adf.cc
  41. +2 −2 vowpalwabbit/cb_explore_adf.h
  42. +42 −28 vowpalwabbit/cbify.cc
  43. +20 −20 vowpalwabbit/classweight.cc
  44. +25 −25 vowpalwabbit/comp_io.cc
  45. +2 −2 vowpalwabbit/comp_io.h
  46. +19 −14 vowpalwabbit/confidence.cc
  47. +0 −2 vowpalwabbit/constant.h
  48. +7 −4 vowpalwabbit/correctedMath.h
  49. +103 −96 vowpalwabbit/cost_sensitive.cc
  50. +18 −9 vowpalwabbit/cost_sensitive.h
  51. +112 −99 vowpalwabbit/cs_active.cc
  52. +172 −154 vowpalwabbit/csoaa.cc
  53. +8 −7 vowpalwabbit/csoaa.h
  54. +68 −70 vowpalwabbit/ect.cc
  55. +13 −12 vowpalwabbit/error_reporting.h
  56. +37 −32 vowpalwabbit/example.cc
  57. +56 −52 vowpalwabbit/example.h
  58. +3 −3 vowpalwabbit/example_predict.cc
  59. +7 −11 vowpalwabbit/example_predict.h
  60. +29 −33 vowpalwabbit/explore_eval.cc
  61. +42 −29 vowpalwabbit/expreplay.h
  62. +214 −98 vowpalwabbit/ezexample.h
  63. +130 −93 vowpalwabbit/feature_group.h
  64. +10 −2 vowpalwabbit/floatbits.h
  65. +56 −55 vowpalwabbit/ftrl.cc
  66. +286 −275 vowpalwabbit/gd.cc
  67. +60 −36 vowpalwabbit/gd.h
  68. +53 −60 vowpalwabbit/gd_mf.cc
  69. +60 −54 vowpalwabbit/gd_predict.h
  70. +47 −41 vowpalwabbit/gen_cs_example.cc
  71. +88 −64 vowpalwabbit/gen_cs_example.h
  72. +29 −28 vowpalwabbit/global_data.cc
  73. +225 −210 vowpalwabbit/global_data.h
  74. +16 −15 vowpalwabbit/interact.cc
  75. +85 −80 vowpalwabbit/interactions.cc
  76. +32 −23 vowpalwabbit/interactions.h
  77. +293 −279 vowpalwabbit/interactions_predict.h
  78. +27 −28 vowpalwabbit/io_buf.cc
  79. +106 −87 vowpalwabbit/io_buf.h
  80. +274 −274 vowpalwabbit/kernel_svm.cc
  81. +16 −11 vowpalwabbit/label_dictionary.cc
  82. +3 −3 vowpalwabbit/label_dictionary.h
  83. +6 −2 vowpalwabbit/label_parser.h
  84. +284 −241 vowpalwabbit/lda_core.cc
  85. +62 −61 vowpalwabbit/learner.cc
  86. +291 −263 vowpalwabbit/learner.h
  87. +110 −110 vowpalwabbit/log_multi.cc
  88. +99 −120 vowpalwabbit/loss_functions.cc
  89. +6 −8 vowpalwabbit/loss_functions.h
  90. +46 −62 vowpalwabbit/lrq.cc
  91. +21 −26 vowpalwabbit/lrqfa.cc
  92. +39 −51 vowpalwabbit/main.cc
  93. +77 −76 vowpalwabbit/marginal.cc
  94. +50 −31 vowpalwabbit/memory.h
  95. +13 −17 vowpalwabbit/mf.cc
  96. +49 −51 vowpalwabbit/multiclass.cc
  97. +9 −4 vowpalwabbit/multiclass.h
  98. +56 −66 vowpalwabbit/multilabel.cc
  99. +8 −5 vowpalwabbit/multilabel.h
  100. +6 −7 vowpalwabbit/multilabel_oaa.cc
  101. +33 −37 vowpalwabbit/mwt.cc
  102. +1 −1 vowpalwabbit/mwt.h
  103. +9 −9 vowpalwabbit/network.cc
  104. +87 −97 vowpalwabbit/nn.cc
  105. +55 −60 vowpalwabbit/no_label.cc
  106. +11 −10 vowpalwabbit/no_label.h
  107. +2 −3 vowpalwabbit/noop.cc
  108. +55 −57 vowpalwabbit/oaa.cc
  109. +139 −142 vowpalwabbit/options.h
  110. +70 −50 vowpalwabbit/options_boost_po.cc
  111. +225 −186 vowpalwabbit/options_boost_po.h
  112. +11 −17 vowpalwabbit/options_serializer_boost_po.cc
  113. +57 −47 vowpalwabbit/options_serializer_boost_po.h
  114. +27 −30 vowpalwabbit/options_types.h
  115. +432 −321 vowpalwabbit/parse_args.cc
  116. +2 −1 vowpalwabbit/parse_args.h
  117. +10 −8 vowpalwabbit/parse_dispatch_loop.h
  118. +90 −70 vowpalwabbit/parse_example.cc
  119. +5 −4 vowpalwabbit/parse_example.h
  120. +0 −1 vowpalwabbit/parse_example_json.cc
  121. +253 −277 vowpalwabbit/parse_example_json.h
  122. +18 −17 vowpalwabbit/parse_primitives.cc
  123. +54 −41 vowpalwabbit/parse_primitives.h
  124. +121 −132 vowpalwabbit/parse_regressor.cc
  125. +2 −1 vowpalwabbit/parse_regressor.h
  126. +121 −160 vowpalwabbit/parser.cc
  127. +19 −16 vowpalwabbit/parser.h
  128. +2 −3 vowpalwabbit/primitives.cc
  129. +2 −2 vowpalwabbit/primitives.h
  130. +6 −4 vowpalwabbit/print.cc
  131. +2 −5 vowpalwabbit/rand48.cc
  132. +0 −1 vowpalwabbit/rand48.h
  133. +165 −219 vowpalwabbit/recall_tree.cc
  134. +5 −5 vowpalwabbit/reductions.h
  135. +21 −17 vowpalwabbit/scorer.cc
  136. +1,232 −833 vowpalwabbit/search.cc
  137. +131 −87 vowpalwabbit/search.h
  138. +328 −295 vowpalwabbit/search_dep_parser.cc
  139. +1 −1 vowpalwabbit/search_dep_parser.h
  140. +142 −106 vowpalwabbit/search_entityrelationtask.cc
  141. +1 −1 vowpalwabbit/search_entityrelationtask.h
  142. +151 −119 vowpalwabbit/search_graph.cc
  143. +1 −1 vowpalwabbit/search_graph.h
  144. +19 −13 vowpalwabbit/search_hooktask.cc
  145. +15 −10 vowpalwabbit/search_hooktask.h
  146. +126 −122 vowpalwabbit/search_meta.cc
  147. +9 −6 vowpalwabbit/search_meta.h
  148. +19 −16 vowpalwabbit/search_multiclasstask.cc
  149. +1 −1 vowpalwabbit/search_multiclasstask.h
  150. +147 −114 vowpalwabbit/search_sequencetask.cc
  151. +5 −5 vowpalwabbit/search_sequencetask.h
  152. +14 −15 vowpalwabbit/sender.cc
  153. +43 −44 vowpalwabbit/simple_label.cc
  154. +3 −2 vowpalwabbit/simple_label.h
  155. +27 −31 vowpalwabbit/spanning_tree.cc
  156. +5 −5 vowpalwabbit/spanning_tree.h
  157. +115 −129 vowpalwabbit/stagewise_poly.cc
  158. +1 −1 vowpalwabbit/stagewise_poly.h
  159. +19 −24 vowpalwabbit/svrg.cc
  160. +14 −19 vowpalwabbit/topk.cc
  161. +1 −1 vowpalwabbit/unique_sort.cc
  162. +124 −81 vowpalwabbit/v_array.h
  163. +89 −58 vowpalwabbit/v_hashmap.h
  164. +53 −41 vowpalwabbit/vw.h
  165. +6 −3 vowpalwabbit/vw_allreduce.h
  166. +17 −31 vowpalwabbit/vw_exception.cc
  167. +68 −64 vowpalwabbit/vw_exception.h
  168. +1 −1 vowpalwabbit/vw_validate.cc
  169. +1 −1 vowpalwabbit/vw_validate.h
  170. +9 −7 vowpalwabbit/vw_versions.h
  171. +69 −71 vowpalwabbit/vwdll.h
@@ -0,0 +1,90 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
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: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

6 build-linux.sh 100644 → 100755
@@ -4,6 +4,11 @@ set -x

export PATH="$HOME/miniconda/bin:$PATH"

# Check if any clang-formatting necessary

cd /vw
./utl/clang-format check

sudo apt remove --yes --force-yes cmake

# Upgrade CMake
@@ -47,3 +52,4 @@ make vw-bin -j ${NUM_PROCESSORS}
cd ..
cd test
export PATH=../build/vowpalwabbit/:$PATH && ./RunTests -d -fe -E 0.001
cd ..
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# Usage (from repo root):
# "./utl/clang-format fix" formats your code.
# "./utl/clang-format check" exits with non-zero if your code isn't formatted correctly.
# Intended to be used with clang-format 7.0.1.

for VW_FILE in $(find vowpalwabbit -type f -name '*.cc' -o -name '*.h'); do

if [ "$1" = check ]; then
diff $VW_FILE <(clang-format $VW_FILE);
if [ $? -ne 0 ]; then
echo "Run \"./utl/clang-format fix\""
exit 1
fi
fi

if [ "$1" = fix ]; then
clang-format -i $VW_FILE;
fi

done
Oops, something went wrong.

0 comments on commit d0c9042

Please sign in to comment.