This option allows cleaning up namespace declaration, by removing the
extra semicolon after namespace closing brace.
Details
Diff Detail
- Build Status
Buildable 6539 Build 6539: arc lint + arc unit
Event Timeline
I think that this is more of a linter check and as such doesn't really belong to clang-format.
@djasper: what do you think about this?
Yes, this definitely does not belong in the NamespaceEndCommentsFixer. It has nothing to do with comments.
And I am also very skeptical about several things:
- Why start here? There are many places where semicolons could be cleaned up.
- If we add more of such cleanup functionality, I think we should pull them out of the general configuration. This isn't really part of a "style".
- We do have some somewhat related functionality to cleanup in the Cleaner class in Format.cpp.
Before going forward with this, I'd like to understand what the long-term plan is.
I stumbled on the issue when working on the CompactNamespaces option, where the extra semicolon prevents merging the closing braces.
There was an easy fix, which guaranteed that the closing braces would be properly merged, so I went for it, just adding an option to keep things generic.
So there wasn't really a "long term" plan (though since I made the fix, I have though that it would be nice to remove other cases of extra semicolon, e.g. after function body).
I did not know of this 'Cleaner' class (I did not actually try to find it either, thruth be told), but it would seem more appropriate indeed. The only thing is I could not find where this is called, and esp. confirm if it happens before the NamespaceEndCommentsFixer.
Back to the point, I can see a few options here:
- Merge this patch into the CompactNamespaces patch, but remove the option and drop the semicolon only when CompactNamespaces mode is enabled
- Rework CompactNamespaces to merge namespace closing brace with extra semicolon (not a big fan, it would look very strange: };})
- Implement this in a more generic fashion, in the Cleaner, with no style option (e.g. always on). Possibly the better option, but may be a more significant significant undertaking
I think we should just not do this for now. This addresses a very infrequent case that's easy enough to fix manually. As such, it's not worth the added complexity of clang-format and potential failures it might generate. Changing non-whitespace/non-comment code is always dangerous.
What's the current behavior of the compact namespaces in the presence of semicolons?
ATM, in the presence of semicolons, the closing braces will simply not be merged : i will check if I can handle this case easily (in the CompactNamespaces patch), and I'll abandon this one for now.
Would it be possible to add a Fixer that removes unneeded semicolon after C function?