cgmb / guardonce

Utilities for converting from C/C++ include guards to #pragma once and back again.
MIT License
142 stars 3 forks source link

Extraneous newline is left at the end of file in some cases #32

Closed Calinou closed 4 years ago

Calinou commented 4 years ago

When running guard2once 2.4.0 on files like this one, it will work correctly but an extraneous newline will be left at the end of file, causing clang-format to fail.

Not a huge issue as clang-format can fix it on its own, but I thought I'd report it anyway :slightly_smiling_face:

Thanks a lot for making this tool, it's a huge time saver.

cgmb commented 4 years ago

If you use guard2once -s, it will remove any extra newlines that would be left at the end of the file after removing the guard. Going the other way, once2guard -l will ensure there's a newline before the endif when converting back. This behaviour should probably be the default. One day, perhaps I'll release a v3 where it is.

When I originally wrote guard2once and once2guard, I designed them to make minimal, symmetric changes with the goal of being able to exactly undo each other whenever possible. In retrospect, I suppose I should have prioritized output that satisfies common lint rules by default. Requiring a flag for such a common need is a usability problem for new users (which is essentially all users), but that is the solution at the moment. See also: Issue #10.

Glad to be of help!