Skip to content

clang-format#283

Merged
serprex merged 1 commit into
mainfrom
clang-format
Jun 16, 2026
Merged

clang-format#283
serprex merged 1 commit into
mainfrom
clang-format

Conversation

@serprex

@serprex serprex commented Jun 15, 2026

Copy link
Copy Markdown
Member

alternative to #278

went with clang 19 because that's what Debian 13 ships

108 column width because on a 13 inch laptop I fit 280 columns & I like 108 as a number

@serprex serprex requested a review from theory June 15, 2026 16:09
@theory

theory commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

I fiddled with it a bit in a745588, generating a format from the Mozilla format with a few tweaks that I prefer:

@@ -75,7 +75,7 @@
 AllowAllParametersOfDeclarationOnNextLine: false
 AllowBreakBeforeNoexceptSpecifier: Never
 AllowBreakBeforeQtProperty: false
-AllowShortBlocksOnASingleLine: Never
+AllowShortBlocksOnASingleLine: Always
 AllowShortCaseExpressionOnASingleLine: true
 AllowShortCaseLabelsOnASingleLine: false
 AllowShortCompoundRequirementOnASingleLine: true
@@ -100,7 +100,7 @@
   AfterControlStatement: Never
   AfterEnum: true
   AfterExternBlock: true
-  AfterFunction: true
+  AfterFunction: false
   AfterNamespace: false
   AfterObjCDeclaration: false
   AfterStruct: true
@@ -117,20 +117,20 @@
 BreakAfterAttributes: Leave
 BreakAfterJavaFieldAnnotations: false
 BreakAfterOpenBracketBracedList: false
-BreakAfterOpenBracketFunction: false
-BreakAfterOpenBracketIf: false
+BreakAfterOpenBracketFunction: true
+BreakAfterOpenBracketIf: true
 BreakAfterOpenBracketLoop: false
 BreakAfterOpenBracketSwitch: false
 BreakAfterReturnType: TopLevel
 BreakArrays: true
 BreakBeforeBinaryOperators: None
-BreakBeforeCloseBracketBracedList: false
-BreakBeforeCloseBracketFunction: false
-BreakBeforeCloseBracketIf: false
+BreakBeforeCloseBracketBracedList: true
+BreakBeforeCloseBracketFunction: true
+BreakBeforeCloseBracketIf: true
 BreakBeforeCloseBracketLoop: false
 BreakBeforeCloseBracketSwitch: false
 BreakBeforeConceptDeclarations: Always
-BreakBeforeBraces: Mozilla
+BreakBeforeBraces: Custom
 BreakBeforeInlineASMColon: OnlyMultiline
 BreakBeforeTemplateCloser: false
 BreakBeforeTernaryOperators: true
@@ -140,11 +140,11 @@
 BreakInheritanceList: BeforeComma
 BreakStringLiterals: true
 BreakTemplateDeclarations: Yes
-ColumnLimit: 80
+ColumnLimit: 88
 CommentPragmas: "^ IWYU pragma:"
 CompactNamespaces: false
-ConstructorInitializerIndentWidth: 2
-ContinuationIndentWidth: 2
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
 Cpp11BracedListStyle: Block
 DerivePointerAlignment: false
 DisableFormat: false
@@ -169,7 +169,7 @@
     Priority: 3
     SortPriority: 0
     CaseSensitive: false
-  - Regex: '.*'
+  - Regex: ".*"
     Priority: 1
     SortPriority: 0
     CaseSensitive: false
@@ -177,16 +177,16 @@
 IncludeIsMainSourceRegex: ""
 IndentAccessModifiers: false
 IndentCaseBlocks: false
-IndentCaseLabels: true
+IndentCaseLabels: false
 IndentExportBlock: true
 IndentExternBlock: AfterExternBlock
 IndentGotoLabels: true
 IndentPPDirectives: None
 IndentRequiresClause: true
-IndentWidth: 2
+IndentWidth: 4
 IndentWrappedFunctionNames: false
-InsertBraces: false
-InsertNewlineAtEOF: false
+InsertBraces: true
+InsertNewlineAtEOF: true
 InsertTrailingCommas: None
 IntegerLiteralSeparator:
   Binary: 0
@@ -221,7 +221,7 @@
   Prefix: Leave
   Suffix: Leave
 ObjCBinPackProtocolList: Auto
-ObjCBlockIndentWidth: 2
+ObjCBlockIndentWidth: 4
 ObjCBreakBeforeNestedBlockParam: true
 ObjCSpaceAfterProperty: true
 ObjCSpaceBeforeProtocolList: false
@@ -307,7 +307,7 @@
   - Q_UNUSED
   - QT_REQUIRE_VERSION
 TableGenBreakInsideDAGArg: DontBreak
-TabWidth: 8
+TabWidth: 4
 UseTab: Never
 VerilogBreakBetweenInstancePorts: true
 WhitespaceSensitiveMacros:

Basically:

  • Tab width 4 and indent 4
  • For long lists of args, put each arg on its own line indented 4 spaces
  • Always insert a brace after an if; no goto fail risks
  • Max width 88 (I aim for 78 for legibility)
  • Don't indent case labels (they are already sooo indented!)

Requires clang-format 22, but we're using a Docker image in pre-commit anyway, so why not?

What do you think?

@theory theory left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed my own biases; thoughts?

Comment thread .pre-commit-config.yaml Outdated

@theory theory left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it like this at least.

@theory theory added the quality Quality controls, testing, test coverage label Jun 15, 2026
@theory theory added the tooling Tools to assist with development, maintenance, release, etc. label Jun 16, 2026
@serprex

serprex commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

lgtm, I was still trying to match pg_bsd_ident as much as I could, but this is more my preference too

Co-authored-by: David E. Wheeler <david.wheeler@clickhouse.com>
@serprex serprex merged commit 48c4fc0 into main Jun 16, 2026
23 checks passed
@serprex serprex deleted the clang-format branch June 16, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quality Quality controls, testing, test coverage tooling Tools to assist with development, maintenance, release, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants