← Back to team overview

kicad-developers team mailing list archive

Re: Pcbnew display origin transforms for v6

 

On 06/05/2019 22:12, Wayne Stambaugh wrote:
On 5/6/2019 5:11 PM, John Beard wrote:
I still suggest to change it to false be default and allow developers to
manually align when they want (and then override the formatter). Then at
least the default behaviour is a valid formatting choice.

That works for me.

Here's a quick patch to make the _clang-format change and make it clear in the style guide that the column aligned method is still permitted when better for readability. The current switch formatting example is already formatted in multi-line style, so that's covered implicitly.

Cheers,

John
>From 7f2ae3c674030c1b22ecbadb9b70149d0e3e64ec Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
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.
---
 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 8836f6a27..1be6fd6f1 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 1a4179264..413c8b571 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
-- 
2.21.0


Follow ups

References