|
|
We mainly use the same rules as the [KDE-project](https://community.kde.org/Policies/Kdelibs_Coding_Style).
|
|
|
One exception is that we allow multiple statements and variables per line.
|
|
|
|
|
|
# Tabs and Indentation
|
|
|
We expand tabs and use (`vim` options):
|
|
|
|
... | ... | @@ -8,7 +11,7 @@ We expand tabs and use (`vim` options): |
|
|
which means that a tab is equal to 4 spaces and the next source code block is indented by 4 spaces.
|
|
|
|
|
|
# Trailing Whitespaces
|
|
|
** Avoid trailing whitespaces:**
|
|
|
**Avoid trailing whitespaces:**
|
|
|
|
|
|
![Auswahl_001](/uploads/39cfd688cc4b3a8bf5819d9fffd723d1/Auswahl_001.png)
|
|
|
|
... | ... | @@ -20,3 +23,26 @@ which can remove trailing whitespaces on save using |
|
|
|
|
|
autocmd BufEnter * EnableStripWhitespaceOnSave
|
|
|
|
|
|
# Code Style Checking
|
|
|
We use the [krazy](https://github.com/Krazy-collection/krazy) Code Checker from `KDE` to make sure that the style rules are not violated.
|
|
|
Here are some examples how to use this tool in practise
|
|
|
|
|
|
```bash
|
|
|
# run crazy to all on current folder and write reults to tofix.txt
|
|
|
krazy2all --exclude copyright,includes --exclude-types cmake,python,kpartgui --extra crud,style,contractions --check-sets foss,c++ --export textedit | grep -v "Multiple statements on 1 line" | tee ~/tofix.txt
|
|
|
|
|
|
# tofix.txt can be loaded using vim -q and use `:w | cn` to step through the list of style issues
|
|
|
vim -q ~/tofix.txt
|
|
|
```
|
|
|
|
|
|
```bash
|
|
|
# checking single files only
|
|
|
krazy2 --explain --exclude copyright,includes --exclude-types cmake,python,kpartgui --extra crud,style,contractions --check-sets foss,c++ freelist.c
|
|
|
```
|
|
|
|
|
|
# Macro and Multiline Issues
|
|
|
If possible consider using the [Do-While Multiline Macro Wrapping](https://bytes.com/topic/c/answers/219859-do-while-0-macro-substitutions).
|
|
|
|
|
|
# Astyle and Automatic Code Formatting
|
|
|
The scripts `scripts/astyle-cmess` executes the [Artistic Style](http://astyle.sourceforge.net/) and some `Perl` call.
|
|
|
It tries to fix code style issues automatically. |