This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Add IndentCaseBlocks option
ClosedPublic

Authored by capn on Jan 6 2020, 8:22 AM.

Details

Summary

The documentation for IndentCaseLabels claimed that the "Switch
statement body is always indented one level more than case labels". This
is technically false for the code block immediately following the label.
Its closing bracket aligns with the start of the label.

If the case label are not indented, it leads to a style where the
closing bracket of the block aligns with the closing bracket of the
switch statement, which can be hard to parse.

This change introduces a new option, IndentCaseBlocks, which when true
treats the block as a scope block (which it technically is).

Diff Detail

Event Timeline

capn created this revision.Jan 6 2020, 8:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2020, 8:22 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Eugene.Zelenko edited reviewers, added: MyDeveloperDay; removed: Restricted Project.Jan 6 2020, 8:57 AM

Could you add an entry into the clang-format section of the clang release notes

clang/unittests/Format/FormatTest.cpp
1235

Could you add a test with indented case labels and indented case blocks?

MyDeveloperDay requested changes to this revision.Jan 7 2020, 12:46 AM
This revision now requires changes to proceed.Jan 7 2020, 12:46 AM
MyDeveloperDay added inline comments.Jan 7 2020, 12:49 PM
clang/unittests/Format/FormatTest.cpp
1235

what happens if there are not braces {}

capn updated this revision to Diff 236690.Jan 7 2020, 2:29 PM

Added release note update and test for both case labels and blocks being indented.

capn updated this revision to Diff 236740.Jan 7 2020, 6:33 PM
capn marked an inline comment as done.

Added case without {} to tests to ensure that still works as expected too.

capn marked an inline comment as done.Jan 7 2020, 6:37 PM

This LGTM, thanks for the patch

MyDeveloperDay accepted this revision.Jan 8 2020, 5:22 AM
This revision is now accepted and ready to land.Jan 8 2020, 5:22 AM
capn added a comment.Jan 8 2020, 6:48 AM

Thanks for the review! I don't have committer access, feel free to land at your convenience.

capn added a comment.Jan 10 2020, 6:53 AM

Ping. Please land on my behalf.

This revision was automatically updated to reflect the committed changes.