[Bf-blender-cvs] [fdf4e63985a] temp-clang-format: clang-format configuration improvements
Campbell Barton
noreply at git.blender.org
Tue Apr 16 11:58:29 CEST 2019
Commit: fdf4e63985ae1dd539d97e41b0644875b3b0c695
Author: Campbell Barton
Date: Tue Apr 16 11:54:55 2019 +0200
Branches: temp-clang-format
https://developer.blender.org/rBfdf4e63985ae1dd539d97e41b0644875b3b0c695
clang-format configuration improvements
Formatting:
- Avoid breaking between assignment and function call.
- Don't right align multi-line string literals.
General:
- Remove overly verbose header (not needed for a config).
- Update examples in comments.
- Add missing iterator macros.
===================================================================
M .clang-format
===================================================================
diff --git a/.clang-format b/.clang-format
index ba34e1b599e..2a78d115d85 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,74 +1,14 @@
-# Copyright 2017 Blender Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy
-# of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-#
-# Clang-format for Blender, as describe in the Blender style guide:
-# https://wiki.blender.org/index.php/Dev:Doc/Code_Style
-#
-# NOTE: Not all Blender style rules are currently supported properly! Take care
-# when using this (see below for details).
-#
-# To apply clang-format to a file, run
-#
-# clang-format -i foo.cpp
-#
-# This will update the file in place.
-#
-# To run on all files on a UNIX system, run
-#
-# ./clang-format-migration.sh
-#
-# NOTE: At time of writing (10/30/2017) not all formatting can be made exactly
-# like current Blender sources, so a few compromises are made:
-#
-# 1. Newline after : in switch statements: clang-format will put the { on
-# the same line. This is due to a limitation in clang-format; it does not
-# support adding the newline after cases in switch statements.
-# 2. Nested preprocessor directives don't get proper indentation after the
-# '#'. See IndentPPDirectives, which is supported in clang-format from
-# LLVM6, but not LLVM5. It is included below but commented out.
-# 3. Special case of { position on if statements where the condition covers
-# more than one line. clang-format is an all or nothing formatter in this
-# case; so unfortunately the case of
-#
-# if (long_condition_here() ||
-# long_condition_here() ||
-# long_condition_here() ||
-# long_condition_here())
-# {
-# ...
-# }
-#
-# will become
-#
-# if (long_condition_here() ||
-# long_condition_here() ||
-# long_condition_here() ||
-# long_condition_here()) {
-# ...
-# }
-#
# Configuration of clang-format
# =============================
+#
+# Tested to work with versions: 6 to 8.
-# This causes parameters on continuations to stack after the open brace,
-# wrapped and indented at a fixed width.
+# This causes parameters on continuations to align to the opening brace.
#
-# like_this_long_name(
-# parameter_one,
-# parameter_two,
-# parameter_three);
+# like_this_long_name(parameter_one,
+# parameter_two,
+# parameter_three);
#
AlignAfterOpenBracket: 'Align'
@@ -79,19 +19,17 @@ AllowShortBlocksOnASingleLine: false
# easier to read and also makes diffs easier to read (since an added or removed
# parameter is obvious). For example, function calls will look like this:
#
-# like_this_long_name(
-# parameter_one,
-# parameter_two,
-# parameter_three,
-# parameter_four,
-# parameter_five,
-# parameter_six);
+# like_this_long_name(parameter_one,
+# parameter_two,
+# parameter_three,
+# parameter_four,
+# parameter_five,
+# parameter_six);
#
-# instead of this
+# Instead of:
#
-# like_this_long_name(
-# parameter_one, parameter_two, parameter_three, parameter_four,
-# parameter_five, parameter_six);
+# like_this_long_name(parameter_one, parameter_two, parameter_three, parameter_four,
+# parameter_five, parameter_six);
#
BinPackArguments: false
BinPackParameters: false
@@ -155,8 +93,9 @@ SpaceInEmptyParentheses: false
# Use two spaces before trailing comments, for example
#
-# foo = bar; /* comment */
+# foo = bar; // comment
#
+# Note that this doesn't work for C-style comments.
SpacesBeforeTrailingComments: 2
# Don't reflow comments, let developers define line breaks.
@@ -173,32 +112,64 @@ IndentWidth: 2
#
# static void foo(...)
#
-# instead of
+# Instead of:
#
# static void
# foo(very long content here that maybe could be stacked)
#
PenaltyReturnTypeOnItsOwnLine: 10000
+# Avoid having function calls broken onto a new line:
+#
+# int a = foo(
+# long, list, of, many, params);
+#
+# Instead of:
+#
+# int a =
+# foo(long, list, of, many, params);
+#
+PenaltyBreakAssignment: 100
+
AllowShortFunctionsOnASingleLine: None
# Disable for now since it complicates initial migration tests,
# TODO: look into enabling this in the future.
SortIncludes: false
-# Don't right align escapted newlines to the right because we have a wide default
+# Don't right align escaped newlines to the right because we have a wide default
AlignEscapedNewlines: DontAlign
+# Always break ...
+#
+# const char *foo =
+# "multi"
+# "line";
+#
+# Instead of:
+#
+# const char *foo = "multi"
+# "line";
+#
+AlwaysBreakBeforeMultilineStrings: true
+
+# We don't want literal strings to break,
+# however clang-format seems to ignore this :(.
+PenaltyBreakString: 1000000
+
# There are macros in Blender for custom for loops; tell Clang to treat them
# like loops rather than an expression, and so put the { on the same line.
ForEachMacros:
- BLI_SMALLSTACK_ITER_BEGIN
- BMO_ITER
+ - BMW_ITER
- BM_FACES_OF_VERT_ITER_BEGIN
- BM_ITER_ELEM
- BM_ITER_MESH
+ - BM_ITER_MESH_INDEX
- BM_ITER_MESH_MUTABLE
- BM_LOOPS_OF_VERT_ITER_BEGIN
+ - BOOST_FOREACH
- CTX_DATA_BEGIN
- DEG_OBJECT_ITER_BEGIN
- DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN
@@ -228,6 +199,9 @@ ForEachMacros:
- FOREACH_VISIBLE_BASE_BEGIN
- FOREACH_VISIBLE_OBJECT_BEGIN
- GHASH_FOREACH_BEGIN
+ - GHASH_ITER
+ - GSET_FOREACH_BEGIN
+ - GSET_ITER
- GP_EDITABLE_STROKES_BEGIN
- GSET_FOREACH_BEGIN
- ITER_BEGIN
@@ -246,3 +220,7 @@ ForEachMacros:
- SEQP_BEGIN
- SEQ_BEGIN
- foreach
+
+# Without this string literals that in-line 'STRINGIFY' behave strangely (a bug?).
+StatementMacros:
+ - STRINGIFY
More information about the Bf-blender-cvs
mailing list