I’m using VS Code for C++ and clang format for formatting. I like to leave several empty lines at the end of every code file, but clang format trims them. My .clang-format file is:
BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 4
AccessModifierOffset: -4
BreakBeforeBraces: Allman
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: All
AllowShortCaseLabelsOnASingleLine: true
PointerAlignment: Left
MaxEmptyLinesToKeep: 10
AlignTrailingComments: true
If I set BasedOnStyle: none
or BasedOnStyle: InheritParentConfig
the problem disappears but formatting doesn’t work at all. As the problem definitely is in my preset of .clang-format how can I correct it to get desired result?
>Solution :
Since clang-format 17: KeepEmptyLinesAtEOF (Boolean
)
Keep empty lines (up to
MaxEmptyLinesToKeep
) at end of file.