This is an archive of the discontinued LLVM Phabricator instance.

clang-format Additional Indent for class blocks
Needs ReviewPublic

Authored by dpayne on Aug 22 2018, 12:52 PM.

Details

Reviewers
klimek
djasper
Summary

Hi,

This is another attempt at fixing the issue describe here https://reviews.llvm.org/D22505. Some code bases will have an extra indent for member variables and functions, while the access modifiers are only indented once. For example,

class MyClass
{
    public:            // 1 level of indent
        int value2;    // 2 levels of indent
    private:           //1 level of indent
        int value3;    // 2 levels of indent
};

The current solution is to use a combination of increasing indent width and setting AccessModifierOffset to a offset. While this might work for some code bases, it has the downside of changing the indent level across the whole project. To fix this I added AdditionalIndentClassBlock, which when true will indent everything within a class block twice. This then could be used with AccessModifierOffset to achieve the desired formatting. By default it is off.

Going off the previous ticket, my goal here was to come up with a way to get this kind of formatting with the least amount of changes to the rest of the formatting rules.

Diff Detail

Repository
rC Clang

Event Timeline

dpayne created this revision.Aug 22 2018, 12:52 PM
dpayne updated this revision to Diff 162129.Aug 22 2018, 10:39 PM

Adding unit tests to check indents, these were mostly taken from the original patch https://reviews.llvm.org/D22505.

dpayne updated this revision to Diff 166057.Sep 18 2018, 6:21 PM

Adding the missing Style member variable.

@djasper @klimek

Are there any comments here about this approach?

Jim added a subscriber: Jim.Dec 16 2019, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2019, 12:54 AM