Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set up clang format to not trim empty lines at the end of C++ files?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since clang-format 17: KeepEmptyLinesAtEOF (Boolean)

Keep empty lines (up to MaxEmptyLinesToKeep) at end of file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading