Skip to content

Instantly share code, notes, and snippets.

@nicklasfrahm
Last active June 17, 2025 21:36
Show Gist options
  • Save nicklasfrahm/4a4fff24381f85ada76ccb651f555e1f to your computer and use it in GitHub Desktop.
Save nicklasfrahm/4a4fff24381f85ada76ccb651f555e1f to your computer and use it in GitHub Desktop.
Opinionated .clang-format for JS boys coming from prettier and stumbling into C++
AccessModifierOffset: 2
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakStringLiterals: false
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
CompactNamespaces: false
IndentCaseLabels: true
IndentWidth: 2
TabWidth: 2
UseTab: Never
@dortamiguel
Copy link

PenaltyReturnTypeOnItsOwnLine

thank you! that is great :)

@jowillianto
Copy link

For anyone looking for the full version :

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html

ColumnLimit: 80
ContinuationIndentWidth: 2
IndentWidth: 2
TabWidth: 2
ConstructorInitializerIndentWidth: 2
IndentCaseLabels: true
PenaltyReturnTypeOnItsOwnLine: 200
UseTab: Never
SortIncludes: true
SortUsingDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
AlignAfterOpenBracket: BlockIndent
AlignOperands: false
AlignTrailingComments: false
BinPackArguments: false
BinPackParameters: false
SpacesInContainerLiterals: false
Cpp11BracedListStyle: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Always
FixNamespaceComments: false
ReflowComments: false
NamespaceIndentation: All
IncludeBlocks: Merge
BreakStringLiterals: false
BreakConstructorInitializers: AfterColon
IndentPPDirectives: BeforeHash
IncludeCategories:
  - Regex: '"[[:alnum:]._-]+"'
    Priority: 1
    SortPriority: 1
  - Regex: '^((<|").*/)'
    Priority: 2
    SortPriority: 2
  - Regex: "<[[:alnum:]._-]+>"
    Priority: 3
    SortPriority: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment