From 89d198659cb6d4b0e74a5c02b81438fb650e2b73 Mon Sep 17 00:00:00 2001 From: John Beard Date: Mon, 6 May 2019 22:23:51 +0100 Subject: [PATCH] Format: Default to switch cases on separate lines by default Currently, the format enforces single lines when possible, but does not enforce readable column-based alignment (and, moreover, *removes* such manually added alignment: switch( m_orientation ) { case PIN_RIGHT: m_orientation = PIN_UP; break; case PIN_UP: m_orientation = PIN_LEFT; break; } Change this to multi-line by default: switch( m_orientation ) { case PIN_RIGHT: m_orientation = PIN_UP; break; case PIN_UP: m_orientation = PIN_LEFT; break; } If the developer wishes for column-aligned single-line cases, this is permitted, but much be done manually: switch( m_orientation ) { case PIN_RIGHT: m_orientation = PIN_DOWN; break; case PIN_UP: m_orientation = PIN_RIGHT; break; } CHANGE: the _clang-format file to reflect this, and add note about manual override in the dev docs. (cherry picked from commit 272c045c37358300011088161f4fe661398e5bb2) --- Documentation/development/coding-style-policy.md | 14 ++++++++++++++ _clang-format | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/development/coding-style-policy.md b/Documentation/development/coding-style-policy.md index 9d75678cd0..35b8da200a 100644 --- a/Documentation/development/coding-style-policy.md +++ b/Documentation/development/coding-style-policy.md @@ -467,6 +467,20 @@ The case statement is to be indented to the same level as the switch. } ~~~~~~~~~~~~~ +It is permitted to place all cases on a single line each, if that makes the +code more readable. This is often done for look-ups or translation functions. In +this case, you will have to manually align for readability as appropriate and +reject clang-format's suggested changes, if you use it: + +~~~~~~~~~~~~~{.cpp} + switch( m_orientation ) + { + case PIN_RIGHT: m_orientation = PIN_UP; break; + case PIN_UP: m_orientation = PIN_LEFT; break; + case PIN_LEFT: m_orientation = PIN_DOWN; break; + case PIN_DOWN: m_orientation = PIN_RIGHT; break; + } +~~~~~~~~~~~~~ # 5. License Statement # {#license_statement} There is a the file copyright.h which you can copy into the top of diff --git a/_clang-format b/_clang-format index 1a4179264e..413c8b5717 100644 --- a/_clang-format +++ b/_clang-format @@ -7,7 +7,7 @@ AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false