Clang-format Inquiry - Member Alignment

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang-format Inquiry - Member Alignment

Yvan Roux via cfe-dev

Thank you in advance for any assistance, this is my first cfe-dev list post, apologies for any disruption.

 

We use clang-format to lint our C++ as well as “auto-fix” as necessary.

 

There is one coding convention which we had to lose given the fact that it seems clang-format doesn’t have any options we can use to allow for it.  Specifically C++ class member alignment.

 

We want to for example be able to format our class members for easier scanning/readability as follows:

 

TypeA      m_memberOne;

LongTypeB* m_memberTwo = nullptr;

bool       m_someFlag = false;

 

Unfortunately if we for example make use of AlignConsecutiveDeclarations local method definitions become aligned as well as locally declared functions, etc.

 

Is there any current mechanism to allow for class member declaration alignment and validation?

 

Best,

 

Corey L.

 

 

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang-format Inquiry - Member Alignment

Yvan Roux via cfe-dev
On Wed, Sep 19, 2018 at 11:34 AM Corey Lucier via cfe-dev <[hidden email]> wrote:

Thank you in advance for any assistance, this is my first cfe-dev list post, apologies for any disruption.

 

We use clang-format to lint our C++ as well as “auto-fix” as necessary.

 

There is one coding convention which we had to lose given the fact that it seems clang-format doesn’t have any options we can use to allow for it.  Specifically C++ class member alignment.

 

We want to for example be able to format our class members for easier scanning/readability as follows:

 

TypeA      m_memberOne;

LongTypeB* m_memberTwo = nullptr;

bool       m_someFlag = false;

 

Unfortunately if we for example make use of AlignConsecutiveDeclarations local method definitions become aligned as well as locally declared functions, etc.


Can you use a code snippet to elaborate what you mean and want here? Are you referring to member functions defined and declared in the class declaration, respectively?

 

Is there any current mechanism to allow for class member declaration alignment and validation?


What does validation mean?

Thanks,
Owen

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang-format Inquiry - Member Alignment

Yvan Roux via cfe-dev

Thanks Owen.

 

Given a class definition:

 

class Rectangle {

  public:

    Rectangle(int,int);

    int area();

  private:

    int    m_width = 0;

    int    m_height = 0

    double m_cornerRadius = 0;

};

 

I’m speaking of aligning the class members only (w/h/cornerradius above).

 

We use clang-format to check that all developers code matches our coding conventions before they check-in, that’s all I meant by validation. If their code doesn’t match the rules we’ve setup, we use clang-format to auto-fix. The problem is with AlignConsecutiveDeclarations it aligns these but also many other things (basically any declaration), which is not what we want.

 

From: Owen Pan <[hidden email]>
Date: Wednesday, September 19, 2018 at 10:05 PM
To: "[hidden email]" <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Subject: Re: [cfe-dev] Clang-format Inquiry - Member Alignment

 

Thank you in advance for any assistance, this is my first cfe-dev list post, apologies for any disruption.

 

We use clang-format to lint our C++ as well as “auto-fix” as necessary.

 

There is one coding convention which we had to lose given the fact that it seems clang-format doesn’t have any options we can use to allow for it.  Specifically C++ class member alignment.

 

We want to for example be able to format our class members for easier scanning/readability as follows:

 

TypeA      m_memberOne;

LongTypeB* m_memberTwo = nullptr;

bool       m_someFlag = false;

 

Unfortunately if we for example make use of AlignConsecutiveDeclarations local method definitions become aligned as well as locally declared functions, etc.

 

Can you use a code snippet to elaborate what you mean and want here? Are you referring to member functions defined and declared in the class declaration, respectively?

 

 

Is there any current mechanism to allow for class member declaration alignment and validation?

 

What does validation mean?

 

Thanks,

Owen


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev