← Back to team overview

kicad-developers team mailing list archive

[PATCH] Add clang-format configuration

 

Hi,

Currently, our preferred code formatting tool is Uncrustify. Uncrustify
is bad. It does things like this:

wxString m_choiceAntialiasingChoices[] =
        {
            _( "No Antialiasing" ),
            _( "Subpixel Antialiasing (High Quality)" ),      _(
                    "Subpixel Antialiasing (Ultra Quality)" ),_( "Supersampling (2x)" ), _(
                    "Supersampling (4x)" )
        };

Yes, that's an actual Uncrustify output with our configuration, posted
on IRC this morning.

Per metacollin's suggestion I looked into clang-format, which does a
MUCH nicer job because it uses clang's parser to actually understand the
code it's formatting. I wrote up a clang-format config following the
KiCad coding style. Here is the output of clang-format on the same code:

wxString m_choiceAntialiasingChoices[] = { _( "No Antialiasing" ),
    _( "Subpixel Antialiasing (High Quality)" ),
    _( "Subpixel Antialiasing (Ultra Quality)" ),
    _( "Supersampling (2x)" ),
    _( "Supersampling (4x)" ) };

It's not perfect, but it's way better than Uncrustify.

The attached patch adds a _clang-format configuration file to the root
of the repository.

-- 
Chris
>From bd6355238dc9fd2c1c193f082ca1dbd2fb875bb7 Mon Sep 17 00:00:00 2001
From: Chris Pavlina <pavlina.chris@xxxxxxxxx>
Date: Mon, 13 Mar 2017 09:28:22 -0400
Subject: [PATCH] Add clang-format configuration

---
 _clang-format | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 _clang-format

diff --git a/_clang-format b/_clang-format
new file mode 100644
index 000000000..6e890e478
--- /dev/null
+++ b/_clang-format
@@ -0,0 +1,53 @@
+BasedOnStyle: LLVM
+AccessModifierOffset: -4
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveDeclarations: true
+AlignEscapedNewlinesLeft: true
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: false
+BinPackParameters: true
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: Allman
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakStringLiterals: false
+ColumnLimit: 100
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ForEachMacros: [ BOOST_FOREACH ]
+IndentCaseLabels: false
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+Language: Cpp
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: Inner
+PointerAlignment: Left
+ReflowComments: false
+SortIncludes: true
+SpaceAfterCStyleCast: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: Never
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: true
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
-- 
2.12.0


Follow ups