[clang] 70cfece - Revert "[clang-format] Add option to remove leading blank lines (#91221)"
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 25 06:14:31 PDT 2024
Author: sstwcw
Date: 2024-06-25T13:12:32Z
New Revision: 70cfece24d6cbb57e35dd961cc97eb2a6bf1e387
URL: https://github.com/llvm/llvm-project/commit/70cfece24d6cbb57e35dd961cc97eb2a6bf1e387
DIFF: https://github.com/llvm/llvm-project/commit/70cfece24d6cbb57e35dd961cc97eb2a6bf1e387.diff
LOG: Revert "[clang-format] Add option to remove leading blank lines (#91221)"
This reverts commit 9267f8f19a2e502ef5a216c0d52b352b3699d399.
I changed a formatter option. I forgot to update other components that
depend on the formatter when the option name changed.
Added:
Modified:
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 080cba90c4a8bf..bb00c20922d361 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4443,51 +4443,23 @@ the configuration (without a prefix: ``Auto``).
false:
import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
-.. _KeepEmptyLines:
-
-**KeepEmptyLines** (``KeepEmptyLinesStyle``) :versionbadge:`clang-format 19` :ref:`¶ <KeepEmptyLines>`
- Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
- consecutive empty lines are kept.
-
- Nested configuration flags:
-
- Options regarding which empty lines are kept.
-
- For example, the config below will remove empty lines at start of the
- file, end of the file, and start of blocks.
-
-
- .. code-block:: c++
-
- KeepEmptyLines:
- AtEndOfFile: false
- AtStartOfBlock: false
- AtStartOfFile: false
-
- * ``bool AtEndOfFile`` Keep empty lines at end of file.
-
- * ``bool AtStartOfBlock`` Keep empty lines at start of a block.
-
- .. code-block:: c++
-
- true: false:
- if (foo) { vs. if (foo) {
- bar();
- bar(); }
- }
-
- * ``bool AtStartOfFile`` Keep empty lines at start of file.
-
-
.. _KeepEmptyLinesAtEOF:
**KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <KeepEmptyLinesAtEOF>`
- This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
+ Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
.. _KeepEmptyLinesAtTheStartOfBlocks:
**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <KeepEmptyLinesAtTheStartOfBlocks>`
- This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
+ If true, the empty line at the start of blocks is kept.
+
+ .. code-block:: c++
+
+ true: false:
+ if (foo) { vs. if (foo) {
+ bar();
+ bar(); }
+ }
.. _LambdaBodyIndentation:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9ed3ff4507671c..df579ae398c5ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1110,8 +1110,6 @@ clang-format
- Adds ``AllowShortCaseExpressionOnASingleLine`` option.
- Adds ``AlignCaseArrows`` suboption to ``AlignConsecutiveShortCaseStatements``.
- Adds ``LeftWithLastLine`` suboption to ``AlignEscapedNewlines``.
-- Adds ``KeepEmptyLines`` option to deprecate ``KeepEmptyLinesAtEOF``
- and ``KeepEmptyLinesAtTheStartOfBlocks``.
libclang
--------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index efc2e450b723fa..7d257be10af42c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3095,49 +3095,20 @@ struct FormatStyle {
bool JavaScriptWrapImports;
// clang-format on
- /// Options regarding which empty lines are kept.
- ///
- /// For example, the config below will remove empty lines at start of the
- /// file, end of the file, and start of blocks.
- ///
- /// \code
- /// KeepEmptyLines:
- /// AtEndOfFile: false
- /// AtStartOfBlock: false
- /// AtStartOfFile: false
- /// \endcode
- struct KeepEmptyLinesStyle {
- /// Keep empty lines at end of file.
- bool AtEndOfFile;
- /// Keep empty lines at start of a block.
- /// \code
- /// true: false:
- /// if (foo) { vs. if (foo) {
- /// bar();
- /// bar(); }
- /// }
- /// \endcode
- bool AtStartOfBlock;
- /// Keep empty lines at start of file.
- bool AtStartOfFile;
- bool operator==(const KeepEmptyLinesStyle &R) const {
- return AtEndOfFile == R.AtEndOfFile &&
- AtStartOfBlock == R.AtStartOfBlock &&
- AtStartOfFile == R.AtStartOfFile;
- }
- };
- /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
- /// consecutive empty lines are kept.
- /// \version 19
- KeepEmptyLinesStyle KeepEmptyLines;
-
- /// This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
+ /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
/// \version 17
- // bool KeepEmptyLinesAtEOF;
+ bool KeepEmptyLinesAtEOF;
- /// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
+ /// If true, the empty line at the start of blocks is kept.
+ /// \code
+ /// true: false:
+ /// if (foo) { vs. if (foo) {
+ /// bar();
+ /// bar(); }
+ /// }
+ /// \endcode
/// \version 3.7
- // bool KeepEmptyLinesAtTheStartOfBlocks;
+ bool KeepEmptyLinesAtTheStartOfBlocks;
/// Indentation logic for lambda bodies.
enum LambdaBodyIndentationKind : int8_t {
@@ -5062,7 +5033,10 @@ struct FormatStyle {
JavaImportGroups == R.JavaImportGroups &&
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
- KeepEmptyLines == R.KeepEmptyLines && Language == R.Language &&
+ KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF &&
+ KeepEmptyLinesAtTheStartOfBlocks ==
+ R.KeepEmptyLinesAtTheStartOfBlocks &&
+ Language == R.Language &&
LambdaBodyIndentation == R.LambdaBodyIndentation &&
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 259ef1dd00e3f9..cd21fbb2221ac6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -369,14 +369,6 @@ template <> struct ScalarEnumerationTraits<FormatStyle::JavaScriptQuoteStyle> {
}
};
-template <> struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
- static void mapping(IO &IO, FormatStyle::KeepEmptyLinesStyle &Value) {
- IO.mapOptional("AtEndOfFile", Value.AtEndOfFile);
- IO.mapOptional("AtStartOfBlock", Value.AtStartOfBlock);
- IO.mapOptional("AtStartOfFile", Value.AtStartOfFile);
- }
-};
-
template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) {
IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);
@@ -877,9 +869,6 @@ template <> struct MappingTraits<FormatStyle> {
OnCurrentLine);
IO.mapOptional("DeriveLineEnding", DeriveLineEnding);
IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
- IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLines.AtEndOfFile);
- IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
- Style.KeepEmptyLines.AtStartOfBlock);
IO.mapOptional("IndentFunctionDeclarationAfterType",
Style.IndentWrappedFunctionNames);
IO.mapOptional("IndentRequires", Style.IndentRequiresClause);
@@ -1015,7 +1004,9 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
- IO.mapOptional("KeepEmptyLines", Style.KeepEmptyLines);
+ IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
+ Style.KeepEmptyLinesAtTheStartOfBlocks);
+ IO.mapOptional("KeepEmptyLinesAtEOF", Style.KeepEmptyLinesAtEOF);
IO.mapOptional("LambdaBodyIndentation", Style.LambdaBodyIndentation);
IO.mapOptional("LineEnding", Style.LineEnding);
IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -1526,11 +1517,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
/*Hex=*/0, /*HexMinDigits=*/0};
LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
LLVMStyle.JavaScriptWrapImports = true;
- LLVMStyle.KeepEmptyLines = {
- /*AtEndOfFile=*/false,
- /*AtStartOfBlock=*/true,
- /*AtStartOfFile=*/true,
- };
+ LLVMStyle.KeepEmptyLinesAtEOF = false;
+ LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
LLVMStyle.LambdaBodyIndentation = FormatStyle::LBI_Signature;
LLVMStyle.Language = Language;
LLVMStyle.LineEnding = FormatStyle::LE_DeriveLF;
@@ -1653,7 +1641,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
{".*", 3, 0, false}};
GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
GoogleStyle.IndentCaseLabels = true;
- GoogleStyle.KeepEmptyLines.AtStartOfBlock = false;
+ GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
GoogleStyle.ObjCSpaceAfterProperty = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = true;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 1804c1437fd41d..729f3d78f4a354 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1478,13 +1478,11 @@ static auto computeNewlines(const AnnotatedLine &Line,
Newlines = std::min(Newlines, 1u);
if (Newlines == 0 && !RootToken.IsFirst)
Newlines = 1;
- if (RootToken.IsFirst &&
- (!Style.KeepEmptyLines.AtStartOfFile || !RootToken.HasUnescapedNewline)) {
+ if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Newlines = 0;
- }
// Remove empty lines after "{".
- if (!Style.KeepEmptyLines.AtStartOfBlock && PreviousLine &&
+ if (!Style.KeepEmptyLinesAtTheStartOfBlocks && PreviousLine &&
PreviousLine->Last->is(tok::l_brace) &&
!PreviousLine->startsWithNamespace() &&
!(PrevPrevLine && PrevPrevLine->startsWithNamespace() &&
@@ -1556,9 +1554,9 @@ void UnwrappedLineFormatter::formatFirstToken(
unsigned NewlineIndent) {
FormatToken &RootToken = *Line.First;
if (RootToken.is(tok::eof)) {
- unsigned Newlines = std::min(
- RootToken.NewlinesBefore,
- Style.KeepEmptyLines.AtEndOfFile ? Style.MaxEmptyLinesToKeep + 1 : 1);
+ unsigned Newlines =
+ std::min(RootToken.NewlinesBefore,
+ Style.KeepEmptyLinesAtEOF ? Style.MaxEmptyLinesToKeep + 1 : 1);
unsigned TokenIndent = Newlines ? NewlineIndent : 0;
Whitespaces->replaceWhitespace(RootToken, Newlines, TokenIndent,
TokenIndent);
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 2466677a3740d3..aded3ed2a6596e 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -178,9 +178,8 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
CHECK_PARSE_BOOL(InsertBraces);
CHECK_PARSE_BOOL(InsertNewlineAtEOF);
- CHECK_PARSE_BOOL_FIELD(KeepEmptyLines.AtEndOfFile, "KeepEmptyLinesAtEOF");
- CHECK_PARSE_BOOL_FIELD(KeepEmptyLines.AtStartOfBlock,
- "KeepEmptyLinesAtTheStartOfBlocks");
+ CHECK_PARSE_BOOL(KeepEmptyLinesAtEOF);
+ CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
CHECK_PARSE_BOOL(Cpp11BracedListStyle);
@@ -227,9 +226,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction);
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord);
CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace);
- CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtEndOfFile);
- CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtStartOfBlock);
- CHECK_PARSE_NESTED_BOOL(KeepEmptyLines, AtStartOfFile);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterControlStatements);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterForeachMacros);
CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions,
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5276e79d759812..db1decb20d626b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -45,10 +45,6 @@ TEST_F(FormatTest, FormatsGlobalStatementsAt0) {
verifyFormat("\nint i;", " \n\t \v \f int i;");
verifyFormat("int i;\nint j;", " int i; int j;");
verifyFormat("int i;\nint j;", " int i;\n int j;");
-
- auto Style = getLLVMStyle();
- Style.KeepEmptyLines.AtStartOfFile = false;
- verifyFormat("int i;", " \n\t \v \f int i;", Style);
}
TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) {
@@ -167,7 +163,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
auto CustomStyle = getLLVMStyle();
CustomStyle.BreakBeforeBraces = FormatStyle::BS_Custom;
CustomStyle.BraceWrapping.AfterNamespace = true;
- CustomStyle.KeepEmptyLines.AtStartOfBlock = false;
+ CustomStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
verifyFormat("namespace N\n"
"{\n"
"\n"
@@ -393,7 +389,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterClass = true;
Style.BraceWrapping.AfterFunction = true;
- Style.KeepEmptyLines.AtStartOfBlock = false;
+ Style.KeepEmptyLinesAtTheStartOfBlocks = false;
verifyFormat("class Foo\n"
"{\n"
@@ -21960,11 +21956,6 @@ TEST_F(FormatTest, HandlesUTF8BOM) {
verifyFormat("\xef\xbb\xbf");
verifyFormat("\xef\xbb\xbf#include <iostream>");
verifyFormat("\xef\xbb\xbf\n#include <iostream>");
-
- auto Style = getLLVMStyle();
- Style.KeepEmptyLines.AtStartOfFile = false;
- verifyFormat("\xef\xbb\xbf#include <iostream>",
- "\xef\xbb\xbf\n#include <iostream>", Style);
}
// FIXME: Encode Cyrillic and CJK characters below to appease MS compilers.
@@ -27239,7 +27230,7 @@ TEST_F(FormatTest, InsertNewlineAtEOF) {
TEST_F(FormatTest, KeepEmptyLinesAtEOF) {
FormatStyle Style = getLLVMStyle();
- Style.KeepEmptyLines.AtEndOfFile = true;
+ Style.KeepEmptyLinesAtEOF = true;
const StringRef Code{"int i;\n\n"};
verifyNoChange(Code, Style);
More information about the cfe-commits
mailing list