diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2024-06-30 00:45:25 +0000 |
---|---|---|
committer | sstwcw <su3e8a96kzlver@posteo.net> | 2024-06-30 01:20:20 +0000 |
commit | 2853a838d22b69f61ed376abbd9ab5e625111f44 (patch) | |
tree | a2a02e37315760cb0c661f535ea7e43b18c77208 /clang/include | |
parent | dd64e4fa2fd72bc806d4b5b9c07fc235053733e3 (diff) | |
download | llvm-2853a838d22b69f61ed376abbd9ab5e625111f44.zip llvm-2853a838d22b69f61ed376abbd9ab5e625111f44.tar.gz llvm-2853a838d22b69f61ed376abbd9ab5e625111f44.tar.bz2 |
[clang-format] Add option to remove leading blank lines (#91221)
The options regarding which blank lines are kept are also aggregated.
The new option is `KeepEmptyLines`.
This patch was initially part of 9267f8f19a2e502e. I neglected to check
the server builds before I added it. It broke clangd. Jie Fu fixed the
problem in 4c91b49bab0728d4. I was unaware of it. I thought the main
branch was still broken. I reverted the first patch in
70cfece24d6cbb57. It broke his fix. He reverted it in
c69ea04fb9738db2. Now the feature is added again including the fix.
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/Format/Format.h | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7d257be..efc2e450 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -3095,20 +3095,49 @@ struct FormatStyle { bool JavaScriptWrapImports; // clang-format on - /// Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file. - /// \version 17 - bool KeepEmptyLinesAtEOF; - - /// If true, the empty line at the start of blocks is kept. + /// 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 - /// true: false: - /// if (foo) { vs. if (foo) { - /// bar(); - /// bar(); } - /// } + /// 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``. + /// \version 17 + // bool KeepEmptyLinesAtEOF; + + /// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``. /// \version 3.7 - bool KeepEmptyLinesAtTheStartOfBlocks; + // bool KeepEmptyLinesAtTheStartOfBlocks; /// Indentation logic for lambda bodies. enum LambdaBodyIndentationKind : int8_t { @@ -5033,10 +5062,7 @@ struct FormatStyle { JavaImportGroups == R.JavaImportGroups && JavaScriptQuotes == R.JavaScriptQuotes && JavaScriptWrapImports == R.JavaScriptWrapImports && - KeepEmptyLinesAtEOF == R.KeepEmptyLinesAtEOF && - KeepEmptyLinesAtTheStartOfBlocks == - R.KeepEmptyLinesAtTheStartOfBlocks && - Language == R.Language && + KeepEmptyLines == R.KeepEmptyLines && Language == R.Language && LambdaBodyIndentation == R.LambdaBodyIndentation && LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin && MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros && |