.clang-format 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # DO NOT COMMIT OR MERGE CODE THAT IS RUN THROUGH THIS TOOL YET.
  2. #
  3. # WE ARE STILL DISCUSSING OUR DESIRED STYLE AND ITERATING ON IT.
  4. # (12 Feb 2020)
  5. ---
  6. Language: Cpp
  7. # Out of all supported styles, LLVM seems closest to our own.
  8. BasedOnStyle: LLVM
  9. ################
  10. #
  11. # Deviations from LLVM's style.
  12. #
  13. ################
  14. # We prefer an indentation width of 4 columns; LLVM likes 2.
  15. ## OVERRIDE FOR COMPARISON
  16. IndentWidth: 2
  17. ## OVERRIDE FOR COMPARISON
  18. ## for now i'm not sorting includes, since that makes every file get touched.
  19. SortIncludes: false
  20. # We prefer 79; llvm likes 80.
  21. ColumnLimit: 79
  22. # Where do we want to put backslashes on multiline macros? Our choices are
  23. # "as far left as possible", "as far right as possible", and "make no changes."
  24. # LLVM defaults to right, but we don't dig that.
  25. AlignEscapedNewlines: Left
  26. # When we see a bunch of things in a row with comments after them, should we
  27. # try to align those comments? Doing so makes some of our code pretty ugly.
  28. AlignTrailingComments: false
  29. # We use a function declaration style much closer to BSD KNF than to LLVM's.
  30. # We say:
  31. # int foo(int x);
  32. # int
  33. # foo(int x)
  34. # {
  35. # ...
  36. # }
  37. # whereas llvm prefers:
  38. # int foo(int x);
  39. # int foo(int x) {
  40. # ...
  41. # }
  42. # or even:
  43. # int foo(int x) { ... }
  44. #
  45. BreakBeforeBraces: Custom
  46. BraceWrapping:
  47. AfterFunction: true
  48. AllowShortFunctionsOnASingleLine: None
  49. AlwaysBreakAfterReturnType: AllDefinitions
  50. # We don't like blocks to start with an empty line.
  51. #
  52. KeepEmptyLinesAtTheStartOfBlocks: false
  53. ################
  54. #
  55. # Tor-specific magic
  56. #
  57. ################
  58. #
  59. # These comments are magical, and should not be changed.
  60. #
  61. CommentPragmas: 'LCOV_EXCL|COVERITY'
  62. #
  63. # Remove duplicate empty lines.
  64. #
  65. MaxEmptyLinesToKeep: 1
  66. #
  67. # Indent preprocessor directives, for clarity.
  68. #
  69. IndentPPDirectives: AfterHash
  70. #
  71. # These introduce an iteration, and work a bit like a for loop.
  72. #
  73. # Note that we can NOT include ones that don't work like "for". For example,
  74. # if the body is an argument to the macro, we can't list it here.
  75. #
  76. ForEachMacros:
  77. - MAP_FOREACH
  78. - MAP_FOREACH_MODIFY
  79. - TOR_SIMPLEQ_FOREACH
  80. - TOR_SIMPLEQ_FOREACH_SAFE
  81. - TOR_SLIST_FOREACH
  82. - TOR_SLIST_FOREACH_SAFE
  83. - TOR_LIST_FOREACH
  84. - TOR_LIST_FOREACH_SAFE
  85. - TOR_TAILQ_FOREACH
  86. - TOR_TAILQ_FOREACH_SAFE
  87. - TOR_TAILQ_FOREACH_REVERSE
  88. - TOR_TAILQ_FOREACH_REVERSE_SAFE
  89. - TOR_CIRCLEQ_FOREACH
  90. - TOR_CIRCLEQ_FOREACH_SAFE
  91. - TOR_CIRCLEQ_FOREACH_REVERSE
  92. - TOR_CIRCLEQ_FOREACH_REVERSE_SAFE
  93. - HT_FOREACH
  94. - SMARTLIST_FOREACH_BEGIN
  95. - DIGESTMAP_FOREACH
  96. - DIGESTMAP_FOREACH_MODIFY
  97. - DIGEST256MAP_FOREACH
  98. - DIGEST256MAP_FOREACH_MODIFY
  99. - SDMAP_FOREACH
  100. - RIMAP_FOREACH
  101. - EIMAP_FOREACH
  102. #
  103. # Omitting:
  104. #
  105. # - SMARTLIST_FOREACH, since the body of the loop is an argument.
  106. #
  107. # This explains how to sort our headers.
  108. #
  109. # This is more complex than it truly should be, but I've edited this till
  110. # compilation still mostly passes.
  111. #
  112. # I'm disabling this, however, since it's a distraction from the other
  113. # formatting issues. See SortIncludes above.
  114. #
  115. IncludeCategories:
  116. - Regex: '^"orconfig.h'
  117. Priority: -30
  118. - Regex: '^"ext/'
  119. Priority: -18
  120. - Regex: '^"lib/'
  121. Priority: -10
  122. - Regex: '^"core/or/or.h'
  123. Priority: -5
  124. - Regex: '^"core/'
  125. Priority: 5
  126. - Regex: '^"feature/'
  127. Priority: 10
  128. - Regex: '^"app/'
  129. Priority: 20
  130. #
  131. # These macros should always cause indentation, as though they were { and }.
  132. #
  133. # Do NOT put macros here unless you want an extra level of indentation between
  134. # them whenever they appear.
  135. #
  136. MacroBlockBegin: "^STMT_BEGIN|TT_STMT_BEGIN$"
  137. MacroBlockEnd: "^STMT_END|TT_STMT_END$"
  138. #
  139. # These macros are interpreted as types.
  140. # (Not supported in my clang-format)
  141. #
  142. # TypenameMacros:
  143. # - "STACK_OF"
  144. ...