CI: add clang-format as a tool

- update the style guide to require braces around blocks
 - add a clang-format file that is pretty close to the
   astyle configuration
This commit is contained in:
Adriaan de Groot 2019-06-11 11:18:48 +02:00
parent 39675655a0
commit 0a1b27fcfa
2 changed files with 41 additions and 4 deletions

33
.clang-format Normal file
View File

@ -0,0 +1,33 @@
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
ColumnLimit: 120
Cpp11BracedListStyle: 'false'
FixNamespaceComments: 'true'
IncludeBlocks: Preserve
IndentWidth: '4'
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: Inner
PointerAlignment: Left
ReflowComments: 'false'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'false'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'true'
SpacesInParentheses: 'true'
SpacesInSquareBrackets: 'true'
Standard: Cpp11
...

View File

@ -56,7 +56,7 @@ some PEP8 guidelines.
* For pointer and reference variable declarations, put a space before the variable name
and no space between the type and the `*` or `&`, e.g. `int* p`.
* `for`, `if`, `else`, `while` and similar statements put the braces on the next line,
if the following block is more than one statement. Use no braces for single statements.
if the following block is more than one statement. Always use braces.
* Function and class definitions have their braces on separate lines.
* A function implementation's return type is on its own line.
* `CamelCase.{cpp,h}` style file names.
@ -86,9 +86,13 @@ MyClass::myMethod( QStringList list, const QString& name )
}
```
You can use the `ci/calamaresstyle` script to run
[astyle](http://astyle.sf.net) on your code and have it formatted the right
way.
You can use `clang-format` (version 7) to have Calamares sources formatted
the right way. There is a `.clang-format` file that specifies the details.
In general:
```
$ clang-format-7 -i -style=file <files>
```
`
**NOTE:** An .editorconfig file is included to assist with formatting. In
order to take advantage of this functionality you will need to acquire the