Describe the bug
Clang-format removes superfluous continuous empty lines. This violates the coding standard that the last line be empty.
Context
Last line being empty is an attempt to end the file with '\n' (0x0a) so that it is a text file (as per POSIX).
On Unix, almost all editors insert a '\n' at the end to make it a text file, but as always, there are ways to remove that extra pesky character at the end of the file.
Expected behavior
This is upto discussion. Is the expected behavior:
If it's the second, using clang-format on the repo would be impossible unless someone modified it to add an option.
Current Behavior
clang-format violates coding guideline and there's nothing in short term we can do about it.
To Reproduce
echo -n "int main() {}" > a.cpp
clang-format -i a.cpp
xxd a.cpp
echo "int main() {}" > a.cpp && echo "" >> a.cpp
clang-format -i a.cpp
xxd a.cpp
Possible Solution
I just dug this up https://reviews.llvm.org/rL314033. Given the commit date and the release history I suspect version 6.0.0 should already have it.
That's weird. I verified (using the steps above) using clang-format version 9
Possible Solution
- Fix coding guideline OR
- send patch to clang-format and change minimum clang-format required to that version
I'd stick with whatever clang-format does because I don't want to have guidelines that are not enforceable. If it cannot/doesn't add an empty line, then we should exclude that from the guidelines.
I quickly skimmed through the style guide and I did not see any mention to adding a new line at the end of the file. We usually just highlight it to user because git and github complain about it.
:+1: Yeah, it'll be a change in PR review feedback only
Most helpful comment
I'd stick with whatever clang-format does because I don't want to have guidelines that are not enforceable. If it cannot/doesn't add an empty line, then we should exclude that from the guidelines.