[RFC,1/2] Add clang format file
Checks
Commit Message
Based off of Linux kernel style with some local modifications
and DPDK foreach macros.
A couple of open questions to be resolved befor merging.
Is GPL license ok for config file (inherited from Linux here)?
Do we want to have per-driver files for some drivers (like MLX5)?
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
.clang-format | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 181 insertions(+)
create mode 100644 .clang-format
Comments
On Wed, Mar 22, 2023 at 10:06:54AM -0700, Stephen Hemminger wrote:
> Based off of Linux kernel style with some local modifications
> and DPDK foreach macros.
>
> A couple of open questions to be resolved befor merging.
> Is GPL license ok for config file (inherited from Linux here)?
> Do we want to have per-driver files for some drivers (like MLX5)?
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> .clang-format | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 181 insertions(+)
> create mode 100644 .clang-format
>
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 000000000000..ad4d30520253
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,181 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# clang-format configuration file. Intended for clang-format >= 11.
> +#
> +# For more information, see:
> +#
> +# Documentation/process/clang-format.rst
> +# https://clang.llvm.org/docs/ClangFormat.html
> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> +#
> +---
> +AccessModifierOffset: -4
> +AlignAfterOpenBracket: Align
This may be partially a matter of personal preference, but I disagree with
using this setting. This sets up line continuations with varaible widths,
and leads to:
* continuation lines being very short if the function name in a wrapped
call is long
* indentation using a mix of tabs and spaces as it tries to line up exactly
on a column with brackets
I think a better option for this setting, which is also aligned with our
coding rules, is for this to be set to "DontAlign" and the
"ContinuationIndentWidth" set to 16, leading to double-tab continuations
(at least in my testing).
/Bruce
On Fri, Mar 24, 2023 at 03:53:25PM +0000, Bruce Richardson wrote:
> On Wed, Mar 22, 2023 at 10:06:54AM -0700, Stephen Hemminger wrote:
> > Based off of Linux kernel style with some local modifications
> > and DPDK foreach macros.
> >
> > A couple of open questions to be resolved befor merging.
> > Is GPL license ok for config file (inherited from Linux here)?
> > Do we want to have per-driver files for some drivers (like MLX5)?
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > .clang-format | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 181 insertions(+)
> > create mode 100644 .clang-format
> >
> > diff --git a/.clang-format b/.clang-format
> > new file mode 100644
> > index 000000000000..ad4d30520253
> > --- /dev/null
> > +++ b/.clang-format
> > @@ -0,0 +1,181 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# clang-format configuration file. Intended for clang-format >= 11.
> > +#
> > +# For more information, see:
> > +#
> > +# Documentation/process/clang-format.rst
> > +# https://clang.llvm.org/docs/ClangFormat.html
> > +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> > +#
> > +---
> > +AccessModifierOffset: -4
> > +AlignAfterOpenBracket: Align
>
> This may be partially a matter of personal preference, but I disagree with
> using this setting. This sets up line continuations with varaible widths,
> and leads to:
> * continuation lines being very short if the function name in a wrapped
> call is long
> * indentation using a mix of tabs and spaces as it tries to line up exactly
> on a column with brackets
+1
i find alignment to open bracket terrible. it also blows out to
multiple line diffs if something like a function name is changed
and there are parameters on following lines.
>
> I think a better option for this setting, which is also aligned with our
> coding rules, is for this to be set to "DontAlign" and the
> "ContinuationIndentWidth" set to 16, leading to double-tab continuations
> (at least in my testing).
>
> /Bruce
new file mode 100644
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/process/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: All
+AlwaysBreakBeforeMultilineStrings: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 100
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*[A-Z_]*FOREACH[A-Z_]*' lib/ drivers/ \
+# | sed "s,^#define \([:space:]]*[A-Z_]*FOREACH[A-Z_]*\)(.*$, - \1," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - CIRBUF_FOREACH
+ - FOREACH_ABS_FUNC_IN_PORT
+ - FOREACH_DEVICE_ON_AUXILARY_BUS
+ - FOREACH_DEVICE_ON_PCIBUS
+ - FOREACH_DEVICE_ON_PLATFORM_BUS
+ - FOREACH_DEVICE_ON_VMBUS
+ - FOREACH_DRIVER_ON_AUXILARY_BUS
+ - FOREACH_DRIVER_ON_PCIBUS
+ - FOREACH_DRIVER_ON_PLATFORM_BUS
+ - FOREACH_DRIVER_ON_VMBUS
+ - FOREACH_SUBDEV
+ - FOREACH_SUBDEV_STATE
+ - ILIST_FOREACH
+ - LIST_FOREACH
+ - LIST_FOREACH_FROM
+ - LIST_FOREACH_FROM_SAFE
+ - LIST_FOREACH_SAFE
+ - MLX5_ETH_FOREACH_DEV
+ - MLX5_IPOOL_FOREACH
+ - MLX5_L3T_FOREACH
+ - ML_AVG_FOREACH_QP
+ - ML_AVG_RESET_FOREACH_QP
+ - ML_MAX_FOREACH_QP
+ - ML_MAX_RESET_FOREACH_QP
+ - ML_MIN_FOREACH_QP
+ - ML_MIN_RESET_FOREACH_QP
+ - PLT_TAILQ_FOREACH_SAFE
+ - RTE_BBDEV_FORWEACH
+ - RTE_DEV_FOREACH
+ - RTE_EAL_DEVARGS_FOREACH
+ - RTE_ETH_FOREACH_DEV
+ - RTE_ETH_FOREACH_DEV_OWNED_BY
+ - RTE_ETH_FOREACH_DEV_SIBLING
+ - RTE_ETH_FOREACH_MATCHING_DEV
+ - RTE_ETH_FOREACH_VALID_DEV
+ - RTE_GPU_FOREACH
+ - RTE_GPU_FOREACH_CHILD
+ - RTE_GPU_FOREACH_PARENT
+ - RTE_LCORE_FOREACH
+ - RTE_LCORE_FOREACH_WORKER
+ - RTE_TAILQ_FOREACH
+ - RTE_TAILQ_FOREACH_SAFE
+ - SILIST_FOREACH
+ - SLIST_FOREACH
+ - SLIST_FOREACH_FROM
+ - SLIST_FOREACH_FROM_SAFE
+ - SLIST_FOREACH_SAFE
+ - STAILQ_FOREACH
+ - TAILQ_FOREACH
+ - TAILQ_FOREACH_ENTRY
+ - TAILQ_FOREACH_ENTRY_SAFE
+ - TAILQ_FOREACH_FROM_SAFE
+ - TAILQ_FOREACH_SAFE
+ - json_array_foreach
+ - json_object_foreach
+ - rte_graph_foreach
+ - rte_graph_foreach_node
+ - vdev_netvsc_foreach_iface
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...