From c600e1a423698023c2c183adc91a9f5b9edba5b2 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 19 Oct 2019 23:47:27 +0200 Subject: [PATCH] Some clang-format tweaks to optimize code style --- .clang-format | 12 ++++++------ doc/development.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 98f3758..5f90faa 100644 --- a/.clang-format +++ b/.clang-format @@ -9,23 +9,23 @@ AllowShortCaseLabelsOnASingleLine: 'false' AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: 'false' AllowShortLoopsOnASingleLine: 'false' -AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: 'false' +AlwaysBreakBeforeMultilineStrings: 'true' BinPackArguments: 'false' BinPackParameters: 'false' BreakBeforeBinaryOperators: None BreakBeforeBraces: Linux BreakBeforeTernaryOperators: 'false' BreakStringLiterals: 'true' -ColumnLimit: '120' -ContinuationIndentWidth: '8' +ColumnLimit: '80' +ContinuationIndentWidth: '4' IncludeBlocks: Preserve -IndentCaseLabels: 'false' +IndentCaseLabels: 'true' IndentPPDirectives: None IndentWidth: '4' IndentWrappedFunctionNames: 'false' -KeepEmptyLinesAtTheStartOfBlocks: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'true' Language: Cpp MaxEmptyLinesToKeep: '1' PointerAlignment: Right diff --git a/doc/development.md b/doc/development.md index e54b702..7d04e18 100644 --- a/doc/development.md +++ b/doc/development.md @@ -160,6 +160,26 @@ if (var == 2) { printf("%d\n", var); ``` +#### Empty line at the start of blocks +There are situations when you want to have an empty line at the start of the block to enhance readability, for example: +``` +if (a && + b && + c) { + d = 5; +} +``` + +Here the assignment aligns with the conditions of the if-black making it hard to read. Better: +``` +if (a && + b && + c) { + + d = 5; +} +``` + #### Includes * Always keep all includes at the top of a header and source file. Exception: Documentation before include guards on header file. @@ -311,6 +331,20 @@ Upper-case with underscore as spacing, proper namespacing to namespace and modul #define EZUSB_DEVICE_VID 0xFFFF ``` +#### Multiple variable declarations +Only one declaration per line which also avoids various errors, for example: +``` +// Nope +char a, b, b; +``` + +``` +// Ok +char a; +char b; +char c; +``` + ### Testing We advice you to write unit tests for all modules that allow proper unit testing. This applies to modules that are not part of the actual hooking process and do not rely on external devices to be available. Add these tests to the