From 4d9839067808405ce79439e7defc77e63c6ea8ac Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 16 May 2023 18:15:56 +0200 Subject: [PATCH] CONTRIBUTING: Do not indent case labels nor blocks Fixes: #188 Signed-off-by: Jakub Jelen Reviewed-by: Norbert Pocs Reviewed-by: Andreas Schneider --- .clang-format | 2 ++ CONTRIBUTING.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/.clang-format b/.clang-format index e2611777..78ca1364 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,4 @@ +--- # https://clang.llvm.org/docs/ClangFormatStyleOptions.html BasedOnStyle: LLVM IndentWidth: 4 @@ -13,6 +14,7 @@ BraceWrapping: BeforeElse: false BeforeWhile: false IndentCaseLabels: false +IndentCaseBlocks: false ColumnLimit: 80 AlignAfterOpenBracket: Align AllowAllParametersOfDeclarationOnNextLine: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2d1a8a17..8e26015c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -478,6 +478,45 @@ Macros like `STATUS_NOT_OK_RETURN` that change control flow (return/goto/etc) from within the macro are considered bad, because they look like function calls that never change control flow. Please do not introduce them. +### Switch/case indentation + +The `case` should not be indented to avoid wasting too much horizontal space. +When the case block contains local variables that need to be wrapped in braces, +they should not be indented again either. + +Good example: + + switch (x) { + case 0: + do_stuff(); + break; + case 1: { + int y; + do_stuff(); + break; + } + default: + do_other_stuff(); + break; + } + +Bad example: + + switch (x) { + case 0: + do_stuff(); + break; + case 1: + { + int y; + do_stuff(); + break; + } + default: + do_other_stuff(); + break; + } + Have fun and happy libssh hacking!