aboutsummaryrefslogtreecommitdiff
path: root/.clang-format
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-12-16 10:58:32 -0500
committerNick Mathewson <nickm@torproject.org>2020-02-06 14:33:05 -0500
commit573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa (patch)
treefa9e5ae84837ab9a6088704a02685f005ec0cd99 /.clang-format
parent5bd86b50b58ffcad48416df6fa6b411e92c4636e (diff)
downloadtor-573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa.tar.gz
tor-573ab70bfe4c6239a3fffda89b1a95e4e7ca10aa.zip
Temporary clang-format configuration and script.
The format is the same as in my previous efforts here. The script is a little tricky, since it invokes both clang-format and codetool, and it makes sure that files do not have a changed mtime unless there is actually some change in the file.
Diffstat (limited to '.clang-format')
-rw-r--r--.clang-format166
1 files changed, 166 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000000..31b76a0025
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,166 @@
+---
+Language: Cpp
+# Out of all supported styles, LLVM seems closest to our own.
+BasedOnStyle: LLVM
+
+################
+#
+# Deviations from LLVM's style.
+#
+################
+
+# We prefer an indentation width of 4 columns; LLVM likes 2.
+## OVERRIDE FOR COMPARISON
+IndentWidth: 2
+
+## OVERRIDE FOR COMPARISON
+## for now i'm not sorting includes, since that makes every file get touched.
+SortIncludes: false
+
+# We prefer 79; llvm likes 80.
+ColumnLimit: 79
+
+# Where do we want to put backslashes on multiline macros? Our choices are
+# "as far left as possible", "as far right as possible", and "make no changes."
+# LLVM defaults to right, but we don't dig that.
+AlignEscapedNewlines: Left
+
+# When we see a bunch of things in a row with comments after them, should we
+# try to align those comments? Doing so makes some of our code pretty ugly.
+AlignTrailingComments: false
+
+# We use a function declaration style much closer to BSD KNF than to LLVM's.
+# We say:
+# int foo(int x);
+# int
+# foo(int x)
+# {
+# ...
+# }
+# whereas llvm prefers:
+# int foo(int x);
+# int foo(int x) {
+# ...
+# }
+# or even:
+# int foo(int x) { ... }
+#
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterFunction: true
+AllowShortFunctionsOnASingleLine: None
+AlwaysBreakAfterReturnType: AllDefinitions
+
+# We don't like blocks to start with an empty line.
+#
+KeepEmptyLinesAtTheStartOfBlocks: false
+
+################
+#
+# Tor-specific magic
+#
+################
+
+#
+# These comments are magical, and should not be changed.
+#
+CommentPragmas: 'LCOV_EXCL|COVERITY'
+
+#
+# Remove duplicate empty lines.
+#
+MaxEmptyLinesToKeep: 1
+
+#
+# Indent preprocessor directives, for clarity.
+#
+IndentPPDirectives: AfterHash
+
+#
+# These introduce an iteration, and work a bit like a for loop.
+#
+# Note that we can NOT include ones that don't work like "for". For example,
+# if the body is an argument to the macro, we can't list it here.
+#
+ForEachMacros:
+ - MAP_FOREACH
+ - MAP_FOREACH_MODIFY
+ - TOR_SIMPLEQ_FOREACH
+ - TOR_SIMPLEQ_FOREACH_SAFE
+ - TOR_SLIST_FOREACH
+ - TOR_SLIST_FOREACH_SAFE
+ - TOR_LIST_FOREACH
+ - TOR_LIST_FOREACH_SAFE
+ - TOR_TAILQ_FOREACH
+ - TOR_TAILQ_FOREACH_SAFE
+ - TOR_TAILQ_FOREACH_REVERSE
+ - TOR_TAILQ_FOREACH_REVERSE_SAFE
+ - TOR_CIRCLEQ_FOREACH
+ - TOR_CIRCLEQ_FOREACH_SAFE
+ - TOR_CIRCLEQ_FOREACH_REVERSE
+ - TOR_CIRCLEQ_FOREACH_REVERSE_SAFE
+ - HT_FOREACH
+ - SMARTLIST_FOREACH_BEGIN
+ - DIGESTMAP_FOREACH
+ - DIGESTMAP_FOREACH_MODIFY
+ - DIGEST256MAP_FOREACH
+ - DIGEST256MAP_FOREACH_MODIFY
+ - SDMAP_FOREACH
+ - RIMAP_FOREACH
+ - EIMAP_FOREACH
+
+#
+# Omitting:
+#
+# - SMARTLIST_FOREACH, since the body of the loop is an argument.
+
+#
+# This explains how to sort our headers.
+#
+# This is more complex than it truly should be, but I've edited this till
+# compilation still mostly passes.
+#
+# I'm disabling this, however, since it's a distraction from the other
+# formatting issues. See SortIncludes above.
+#
+IncludeCategories:
+ - Regex: '^"orconfig.h'
+ Priority: -30
+ - Regex: '^"ext/'
+ Priority: -18
+ - Regex: '^"lib/'
+ Priority: -10
+ - Regex: '^"core/or/or.h'
+ Priority: -5
+ - Regex: '^"core/'
+ Priority: 5
+ - Regex: '^"feature/'
+ Priority: 10
+ - Regex: '^"app/'
+ Priority: 20
+
+#
+# These macros should always cause indentation, as though they were { and }.
+#
+# Do NOT put macros here unless you want an extra level of indentation between
+# them whenever they appear.
+#
+MacroBlockBegin: "^STMT_BEGIN|TT_STMT_BEGIN$"
+MacroBlockEnd: "^STMT_END|TT_STMT_END$"
+
+#
+# These macros don't need to have semicolons afterwards.
+#
+StatementMacros:
+ - HT_PROTOTYPE
+ - HT_GENERATE
+ - HT_GENERATE2
+
+#
+# These macros are interpreted as types.
+# (Not supported in my clang-format)
+#
+# TypenameMacros:
+# - "STACK_OF"
+
+...