Skip to content

Commit 8fbb673

Browse files
sstwcwAlexisPerry
authored andcommitted
Revert "[clang-format] Add option to remove leading blank lines (llvm#91221)"
This reverts commit 9267f8f. I changed a formatter option. I forgot to update other components that depend on the formatter when the option name changed.
1 parent 1cfae3b commit 8fbb673

File tree

7 files changed

+41
-124
lines changed

7 files changed

+41
-124
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4443,51 +4443,23 @@ the configuration (without a prefix: ``Auto``).
44434443
false:
44444444
import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
44454445
4446-
.. _KeepEmptyLines:
4447-
4448-
**KeepEmptyLines** (``KeepEmptyLinesStyle``) :versionbadge:`clang-format 19` :ref:`<KeepEmptyLines>`
4449-
Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
4450-
consecutive empty lines are kept.
4451-
4452-
Nested configuration flags:
4453-
4454-
Options regarding which empty lines are kept.
4455-
4456-
For example, the config below will remove empty lines at start of the
4457-
file, end of the file, and start of blocks.
4458-
4459-
4460-
.. code-block:: c++
4461-
4462-
KeepEmptyLines:
4463-
AtEndOfFile: false
4464-
AtStartOfBlock: false
4465-
AtStartOfFile: false
4466-
4467-
* ``bool AtEndOfFile`` Keep empty lines at end of file.
4468-
4469-
* ``bool AtStartOfBlock`` Keep empty lines at start of a block.
4470-
4471-
.. code-block:: c++
4472-
4473-
true: false:
4474-
if (foo) { vs. if (foo) {
4475-
bar();
4476-
bar(); }
4477-
}
4478-
4479-
* ``bool AtStartOfFile`` Keep empty lines at start of file.
4480-
4481-
44824446
.. _KeepEmptyLinesAtEOF:
44834447

44844448
**KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`<KeepEmptyLinesAtEOF>`
4485-
This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
4449+
Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
44864450

44874451
.. _KeepEmptyLinesAtTheStartOfBlocks:
44884452

44894453
**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<KeepEmptyLinesAtTheStartOfBlocks>`
4490-
This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
4454+
If true, the empty line at the start of blocks is kept.
4455+
4456+
.. code-block:: c++
4457+
4458+
true: false:
4459+
if (foo) { vs. if (foo) {
4460+
bar();
4461+
bar(); }
4462+
}
44914463

44924464
.. _LambdaBodyIndentation:
44934465

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,6 @@ clang-format
11101110
- Adds ``AllowShortCaseExpressionOnASingleLine`` option.
11111111
- Adds ``AlignCaseArrows`` suboption to ``AlignConsecutiveShortCaseStatements``.
11121112
- Adds ``LeftWithLastLine`` suboption to ``AlignEscapedNewlines``.
1113-
- Adds ``KeepEmptyLines`` option to deprecate ``KeepEmptyLinesAtEOF``
1114-
and ``KeepEmptyLinesAtTheStartOfBlocks``.
11151113

11161114
libclang
11171115
--------

clang/include/clang/Format/Format.h

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,49 +3095,20 @@ struct FormatStyle {
30953095
bool JavaScriptWrapImports;
30963096
// clang-format on
30973097

3098-
/// Options regarding which empty lines are kept.
3099-
///
3100-
/// For example, the config below will remove empty lines at start of the
3101-
/// file, end of the file, and start of blocks.
3102-
///
3103-
/// \code
3104-
/// KeepEmptyLines:
3105-
/// AtEndOfFile: false
3106-
/// AtStartOfBlock: false
3107-
/// AtStartOfFile: false
3108-
/// \endcode
3109-
struct KeepEmptyLinesStyle {
3110-
/// Keep empty lines at end of file.
3111-
bool AtEndOfFile;
3112-
/// Keep empty lines at start of a block.
3113-
/// \code
3114-
/// true: false:
3115-
/// if (foo) { vs. if (foo) {
3116-
/// bar();
3117-
/// bar(); }
3118-
/// }
3119-
/// \endcode
3120-
bool AtStartOfBlock;
3121-
/// Keep empty lines at start of file.
3122-
bool AtStartOfFile;
3123-
bool operator==(const KeepEmptyLinesStyle &R) const {
3124-
return AtEndOfFile == R.AtEndOfFile &&
3125-
AtStartOfBlock == R.AtStartOfBlock &&
3126-
AtStartOfFile == R.AtStartOfFile;
3127-
}
3128-
};
3129-
/// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3130-
/// consecutive empty lines are kept.
3131-
/// \version 19
3132-
KeepEmptyLinesStyle KeepEmptyLines;
3133-
3134-
/// This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3098+
/// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
31353099
/// \version 17
3136-
// bool KeepEmptyLinesAtEOF;
3100+
bool KeepEmptyLinesAtEOF;
31373101

3138-
/// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
3102+
/// If true, the empty line at the start of blocks is kept.
3103+
/// \code
3104+
/// true: false:
3105+
/// if (foo) { vs. if (foo) {
3106+
/// bar();
3107+
/// bar(); }
3108+
/// }
3109+
/// \endcode
31393110
/// \version 3.7
3140-
// bool KeepEmptyLinesAtTheStartOfBlocks;
3111+
bool KeepEmptyLinesAtTheStartOfBlocks;
31413112

31423113
/// Indentation logic for lambda bodies.
31433114
enum LambdaBodyIndentationKind : int8_t {
@@ -5062,7 +5033,10 @@ struct FormatStyle {
50625033
JavaImportGroups == R.JavaImportGroups &&
50635034
JavaScriptQuotes == R.JavaScriptQuotes &&
50645035
JavaScriptWrapImports == R.JavaScriptWrapImports &&
5065-
KeepEmptyLines == R.KeepEmptyLines && Language == R.Language &&
5036+
KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF &&
5037+
KeepEmptyLinesAtTheStartOfBlocks ==
5038+
R.KeepEmptyLinesAtTheStartOfBlocks &&
5039+
Language == R.Language &&
50665040
LambdaBodyIndentation == R.LambdaBodyIndentation &&
50675041
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
50685042
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&

clang/lib/Format/Format.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,6 @@ template <> struct ScalarEnumerationTraits<FormatStyle::JavaScriptQuoteStyle> {
369369
}
370370
};
371371

372-
template <> struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
373-
static void mapping(IO &IO, FormatStyle::KeepEmptyLinesStyle &Value) {
374-
IO.mapOptional("AtEndOfFile", Value.AtEndOfFile);
375-
IO.mapOptional("AtStartOfBlock", Value.AtStartOfBlock);
376-
IO.mapOptional("AtStartOfFile", Value.AtStartOfFile);
377-
}
378-
};
379-
380372
template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
381373
static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) {
382374
IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);
@@ -877,9 +869,6 @@ template <> struct MappingTraits<FormatStyle> {
877869
OnCurrentLine);
878870
IO.mapOptional("DeriveLineEnding", DeriveLineEnding);
879871
IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
880-
IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLines.AtEndOfFile);
881-
IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
882-
Style.KeepEmptyLines.AtStartOfBlock);
883872
IO.mapOptional("IndentFunctionDeclarationAfterType",
884873
Style.IndentWrappedFunctionNames);
885874
IO.mapOptional("IndentRequires", Style.IndentRequiresClause);
@@ -1015,7 +1004,9 @@ template <> struct MappingTraits<FormatStyle> {
10151004
IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
10161005
IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
10171006
IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
1018-
IO.mapOptional("KeepEmptyLines", Style.KeepEmptyLines);
1007+
IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
1008+
Style.KeepEmptyLinesAtTheStartOfBlocks);
1009+
IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLinesAtEOF);
10191010
IO.mapOptional("LambdaBodyIndentation", Style.LambdaBodyIndentation);
10201011
IO.mapOptional("LineEnding", Style.LineEnding);
10211012
IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -1526,11 +1517,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
15261517
/*Hex=*/0, /*HexMinDigits=*/0};
15271518
LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
15281519
LLVMStyle.JavaScriptWrapImports = true;
1529-
LLVMStyle.KeepEmptyLines = {
1530-
/*AtEndOfFile=*/false,
1531-
/*AtStartOfBlock=*/true,
1532-
/*AtStartOfFile=*/true,
1533-
};
1520+
LLVMStyle.KeepEmptyLinesAtEOF = false;
1521+
LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
15341522
LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
15351523
LLVMStyle.Language = Language;
15361524
LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
@@ -1653,7 +1641,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
16531641
{".*", 3, 0, false}};
16541642
GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
16551643
GoogleStyle.IndentCaseLabels = true;
1656-
GoogleStyle.KeepEmptyLines.AtStartOfBlock = false;
1644+
GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
16571645
GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
16581646
GoogleStyle.ObjCSpaceAfterProperty = false;
16591647
GoogleStyle.ObjCSpaceBeforeProtocolList = true;

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,13 +1478,11 @@ static auto computeNewlines(const AnnotatedLine &Line,
14781478
Newlines = std::min(Newlines, 1u);
14791479
if (Newlines == 0 && !RootToken.IsFirst)
14801480
Newlines = 1;
1481-
if (RootToken.IsFirst &&
1482-
(!Style.KeepEmptyLines.AtStartOfFile || !RootToken.HasUnescapedNewline)) {
1481+
if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
14831482
Newlines = 0;
1484-
}
14851483

14861484
// Remove empty lines after "{".
1487-
if (!Style.KeepEmptyLines.AtStartOfBlock && PreviousLine &&
1485+
if (!Style.KeepEmptyLinesAtTheStartOfBlocks && PreviousLine &&
14881486
PreviousLine->Last->is(tok::l_brace) &&
14891487
!PreviousLine->startsWithNamespace() &&
14901488
!(PrevPrevLine && PrevPrevLine->startsWithNamespace() &&
@@ -1556,9 +1554,9 @@ void UnwrappedLineFormatter::formatFirstToken(
15561554
unsigned NewlineIndent) {
15571555
FormatToken &RootToken = *Line.First;
15581556
if (RootToken.is(tok::eof)) {
1559-
unsigned Newlines = std::min(
1560-
RootToken.NewlinesBefore,
1561-
Style.KeepEmptyLines.AtEndOfFile ? Style.MaxEmptyLinesToKeep + 1 : 1);
1557+
unsigned Newlines =
1558+
std::min(RootToken.NewlinesBefore,
1559+
Style.KeepEmptyLinesAtEOF ? Style.MaxEmptyLinesToKeep + 1 : 1);
15621560
unsigned TokenIndent = Newlines ? NewlineIndent : 0;
15631561
Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
15641562
TokenIndent);

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
178178
CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
179179
CHECK_PARSE_BOOL(InsertBraces);
180180
CHECK_PARSE_BOOL(InsertNewlineAtEOF);
181-
CHECK_PARSE_BOOL_FIELD(KeepEmptyLines.AtEndOfFile, "KeepEmptyLinesAtEOF");
182-
CHECK_PARSE_BOOL_FIELD(KeepEmptyLines.AtStartOfBlock,
183-
"KeepEmptyLinesAtTheStartOfBlocks");
181+
CHECK_PARSE_BOOL(KeepEmptyLinesAtEOF);
182+
CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
184183
CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
185184
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
186185
CHECK_PARSE_BOOL(Cpp11BracedListStyle);
@@ -227,9 +226,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
227226
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
228227
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
229228
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace);
230-
CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtEndOfFile);
231-
CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtStartOfBlock);
232-
CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtStartOfFile);
233229
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterControlStatements);
234230
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterForeachMacros);
235231
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ TEST_F(FormatTest, FormatsGlobalStatementsAt0) {
4545
verifyFormat("\nint i;", " \n\t \v \f int i;");
4646
verifyFormat("int i;\nint j;", " int i; int j;");
4747
verifyFormat("int i;\nint j;", " int i;\n int j;");
48-
49-
auto Style = getLLVMStyle();
50-
Style.KeepEmptyLines.AtStartOfFile = false;
51-
verifyFormat("int i;", " \n\t \v \f int i;", Style);
5248
}
5349

5450
TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) {
@@ -167,7 +163,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
167163
auto CustomStyle = getLLVMStyle();
168164
CustomStyle.BreakBeforeBraces = FormatStyle::BS_Custom;
169165
CustomStyle.BraceWrapping.AfterNamespace = true;
170-
CustomStyle.KeepEmptyLines.AtStartOfBlock = false;
166+
CustomStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
171167
verifyFormat("namespace N\n"
172168
"{\n"
173169
"\n"
@@ -393,7 +389,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
393389
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
394390
Style.BraceWrapping.AfterClass = true;
395391
Style.BraceWrapping.AfterFunction = true;
396-
Style.KeepEmptyLines.AtStartOfBlock = false;
392+
Style.KeepEmptyLinesAtTheStartOfBlocks = false;
397393

398394
verifyFormat("class Foo\n"
399395
"{\n"
@@ -21960,11 +21956,6 @@ TEST_F(FormatTest, HandlesUTF8BOM) {
2196021956
verifyFormat("\xef\xbb\xbf");
2196121957
verifyFormat("\xef\xbb\xbf#include <iostream>");
2196221958
verifyFormat("\xef\xbb\xbf\n#include <iostream>");
21963-
21964-
auto Style = getLLVMStyle();
21965-
Style.KeepEmptyLines.AtStartOfFile = false;
21966-
verifyFormat("\xef\xbb\xbf#include <iostream>",
21967-
"\xef\xbb\xbf\n#include <iostream>", Style);
2196821959
}
2196921960

2197021961
// FIXME: Encode Cyrillic and CJK characters below to appease MS compilers.
@@ -27239,7 +27230,7 @@ TEST_F(FormatTest, InsertNewlineAtEOF) {
2723927230

2724027231
TEST_F(FormatTest, KeepEmptyLinesAtEOF) {
2724127232
FormatStyle Style = getLLVMStyle();
27242-
Style.KeepEmptyLines.AtEndOfFile = true;
27233+
Style.KeepEmptyLinesAtEOF = true;
2724327234

2724427235
const StringRef Code{"int i;\n\n"};
2724527236
verifyNoChange(Code, Style);

0 commit comments

Comments
 (0)