Pcl: Clang-format and last empty line

Created on 23 Mar 2020  路  5Comments  路  Source: PointCloudLibrary/pcl


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).

  1. Text files have 0 or more lines
  2. Each line has 1 or more chars and ends with '\n'

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:

  • end file with '\n' OR
  • end file with "\n\n" (aka empty line)

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

  1. Proof that clang-format doesn't add a '\n' at the end of the file
echo -n "int main() {}" > a.cpp
clang-format -i a.cpp
xxd a.cpp
  1. Proof that clang-format removes multiple '\n' at the end of the file
echo "int main() {}" > a.cpp && echo "" >> a.cpp
clang-format -i a.cpp
xxd a.cpp

Possible Solution

  1. Fix coding guideline OR
  2. send patch to clang-format and change minimum clang-format required to that version
bug

Most helpful comment

Possible Solution

  1. Fix coding guideline OR
  2. 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.

All 5 comments

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

  1. Fix coding guideline OR
  2. 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nh2 picture nh2  路  5Comments

SunBlack picture SunBlack  路  3Comments

dooxe picture dooxe  路  3Comments

SergioRAgostinho picture SergioRAgostinho  路  4Comments

jacquelinekay picture jacquelinekay  路  5Comments