netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH] clang-format: add clang-format configuration file from Linux kernel
@ 2023-08-23  7:11 Thomas Haller
  2023-08-24  7:05 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Haller @ 2023-08-23  7:11 UTC (permalink / raw)
  To: NetFilter; +Cc: Thomas Haller

Clang-format is useful for developing, even if the code base does not
enforce an automated style. With this, I can select a function in the
editor, and reformat that portion with clang-format. In particular, it
can fix indentation and tabs.

The style of nftables is close to kernel style, so take the file from
Linux v6.4 ([1]). There are no changes, except (manually) adjusting
"ForEachMacros".

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/.clang-format?id=6995e2de6891c724bfeb2db33d7b87775f913ad1

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 .clang-format | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 .clang-format

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000000..a86479ce053a
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,140 @@
+# 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: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: 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: 80
+CommentPragmas: '^ IWYU pragma:'
+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:]]*for_each[^[:space:]]*(' include/ tools/ \
+#   | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$,  - '\1'," \
+#   | LC_ALL=C sort -u
+ForEachMacros:
+  - 'hlist_for_each'
+  - 'hlist_for_each_entry'
+  - 'hlist_for_each_entry_continue'
+  - 'hlist_for_each_entry_from'
+  - 'hlist_for_each_entry_safe'
+  - 'hlist_for_each_safe'
+  - 'list_for_each_entry'
+  - 'list_for_each_entry_continue'
+  - 'list_for_each_entry_continue_reverse'
+  - 'list_for_each_entry_from'
+  - 'list_for_each_entry_reverse'
+  - 'list_for_each_entry_safe'
+  - 'list_for_each_entry_safe_continue'
+  - 'list_for_each_entry_safe_from'
+  - 'list_for_each_entry_safe_reverse'
+
+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
+...
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] clang-format: add clang-format configuration file from Linux kernel
  2023-08-23  7:11 [nft PATCH] clang-format: add clang-format configuration file from Linux kernel Thomas Haller
@ 2023-08-24  7:05 ` Pablo Neira Ayuso
  2023-08-24  7:43   ` Thomas Haller
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2023-08-24  7:05 UTC (permalink / raw)
  To: Thomas Haller; +Cc: NetFilter

Hi Thomas,

On Wed, Aug 23, 2023 at 09:11:31AM +0200, Thomas Haller wrote:
> Clang-format is useful for developing, even if the code base does not
> enforce an automated style. With this, I can select a function in the
> editor, and reformat that portion with clang-format. In particular, it
> can fix indentation and tabs.
> 
> The style of nftables is close to kernel style, so take the file from
> Linux v6.4 ([1]). There are no changes, except (manually) adjusting
> "ForEachMacros".

I'd prefer you keep this locally by now.

If more developers are relying on this feature, we can revisit later.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] clang-format: add clang-format configuration file from Linux kernel
  2023-08-24  7:05 ` Pablo Neira Ayuso
@ 2023-08-24  7:43   ` Thomas Haller
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Haller @ 2023-08-24  7:43 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: NetFilter

On Thu, 2023-08-24 at 09:05 +0200, Pablo Neira Ayuso wrote:
> Hi Thomas,
> 
> On Wed, Aug 23, 2023 at 09:11:31AM +0200, Thomas Haller wrote:
> > Clang-format is useful for developing, even if the code base does
> > not
> > enforce an automated style. With this, I can select a function in
> > the
> > editor, and reformat that portion with clang-format. In particular,
> > it
> > can fix indentation and tabs.
> > 
> > The style of nftables is close to kernel style, so take the file
> > from
> > Linux v6.4 ([1]). There are no changes, except (manually) adjusting
> > "ForEachMacros".
> 
> I'd prefer you keep this locally by now.
> 
> If more developers are relying on this feature, we can revisit later.
> 


Hi Pablo,

OK.

If anybody is interested, I solved this on my end, by having nftables
checked out in a subdirectory like

  nftables
  ├── .clang-format
  └── nftables
      ├── aclocal.m4
      ├── ...



And for the record, these were the patches that introduced the file to
kernel and the documentation in kernel:

 - [PATCH] clang-format: add configuration file
   https://lore.kernel.org/lkml/20180312233952.niz2cuz7psv4fe2s@gmail.com/

 - [PATCH v2] clang-format: add configuration file
   https://lore.kernel.org/lkml/20180318171632.qfkemw3mwbcukth6@gmail.com/

 - Linux Documentation/process
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/process/clang-format.rst?id=v6.4


Thanks,
Thomas


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-24  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23  7:11 [nft PATCH] clang-format: add clang-format configuration file from Linux kernel Thomas Haller
2023-08-24  7:05 ` Pablo Neira Ayuso
2023-08-24  7:43   ` Thomas Haller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).