[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 07:41:18 PDT 2024


sstwcw wrote:

Should I make dropping leading blank lines the default?

There are some tests verifying that files that start with newlines should still start with newlines after being formatted.  However, they seem to be there to prevent the newlines from moving to wrong places.

There is 303baf53b1 "skip empty lines and comments in the top of the code when inserting new headers".

```C++
  std::string Code = "\nint x;";
  std::string Expected = "\n#include \"fix.h\"\n"
                         "#include \"a.h\"\n"
                         "#include \"b.h\"\n"
                         "#include \"c.h\"\n"
                         "#include <list>\n"
                         "#include <vector>\n"
                         "int x;";
  tooling::Replacements Replaces = toReplacements(
      {createInsertion("#include \"a.h\""), createInsertion("#include \"c.h\""),
       createInsertion("#include \"b.h\""),
       createInsertion("#include <vector>"), createInsertion("#include <list>"),
       createInsertion("#include \"fix.h\"")});
  EXPECT_EQ(Expected, formatAndApply(Code, Replaces));
```

There is also a test for preserving the byte order mark.

```C++
  verifyFormat("\xef\xbb\xbf\n#include <iostream>");
```

https://github.com/llvm/llvm-project/pull/91221


More information about the cfe-commits mailing list