clang-format: Remove empty lines at the beginning of blocks.

They very rarely aid readability.

Formatting:
  void f() {

    if (a) {

      f();

    }

  }

Now leads to:
  void f() {
    if (a) {
      f();
    }
  }

llvm-svn: 204460
This commit is contained in:
Daniel Jasper 2014-03-21 12:58:53 +00:00
parent 8455c44e6c
commit 11164bdaf5
2 changed files with 20 additions and 0 deletions

View File

@ -888,6 +888,10 @@ private:
if (Newlines == 0 && !RootToken.IsFirst)
Newlines = 1;
// Remove empty lines after "{".
if (PreviousLine && PreviousLine->Last->is(tok::l_brace))
Newlines = 1;
// Insert extra new line before access specifiers.
if (PreviousLine && PreviousLine->Last->isOneOf(tok::semi, tok::r_brace) &&
RootToken.isAccessSpecifier() && RootToken.NewlinesBefore == 1)

View File

@ -174,6 +174,22 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"\n"
"};"));
// Remove empty lines at the beginning and end of blocks.
EXPECT_EQ("void f() {\n"
" if (a) {\n"
" f();\n"
" }\n"
"}",
format("void f() {\n"
"\n"
" if (a) {\n"
"\n"
" f();\n"
"\n"
" }\n"
"\n"
"}"));
// Don't remove empty lines in more complex control statements.
EXPECT_EQ("void f() {\n"
" if (a) {\n"