# Automatic JUCE-like code formatting with clang-format

**URL:** <https://forum.juce.com/t/automatic-juce-like-code-formatting-with-clang-format/31624>\
**Category:** Useful Tools and Components\
**Created:** [February 5, 2019, 3:36pm UTC](https://forum.juce.com/t/automatic-juce-like-code-formatting-with-clang-format/31624 "2019-02-05T15:36:51Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [September 12, 2019, 5:12pm UTC](https://forum.juce.com/t/automatic-juce-like-code-formatting-with-clang-format/31624/13 "2019-09-12T17:12:36Z")

</div>

As I mentioned above, I got a couple of patches merged, but I haven’t got the fix for spacing around curly-braces merged yet. The version of `clang-format` in homebrew seems to be from January, so I guess building from source is still the best way to get an up-to-date version.

The `.clang-format` config file I’ve been using looks like this. You could try it out with whatever clang-format binary you’re able to access, and just remove any keys that clang-format chokes on.

```auto
---
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'false'
AlignOperands: 'true'
AlignTrailingComments: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakAfterJavaFieldAnnotations: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'false'
BreakStringLiterals: 'false'
ColumnLimit: '0'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
DisableFormat: 'false'
ExperimentalAutoDetectBinPacking: 'false'
IndentCaseLabels: 'true'
IndentWidth: '4'
IndentWrappedFunctionNames: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: 'false'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: NonEmpty
SpaceBeforeParens: NonEmptyParentheses
SpaceInEmptyParentheses: 'false'
SpacesBeforeInheritanceColon: 2
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'true'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never

...

```

---

_[View the full topic](https://forum.juce.com/t/automatic-juce-like-code-formatting-with-clang-format/31624)._
