This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Add option to remove semicolon at end of namespace
AbandonedPublic

Authored by Typz on May 18 2017, 4:49 AM.

Details

Reviewers
krasimir
djasper
Summary

This option allows cleaning up namespace declaration, by removing the
extra semicolon after namespace closing brace.

Event Timeline

Typz created this revision.May 18 2017, 4:49 AM
krasimir edited edge metadata.May 18 2017, 4:53 AM

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?

Typz added a comment.May 18 2017, 5:37 AM

Is this not the same reasoning as the whole NamespaceEndCommentsFixer?

djasper edited edge metadata.May 18 2017, 11:31 PM

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.

Typz added a comment.May 19 2017, 12:44 AM

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?

Typz abandoned this revision.May 19 2017, 6:01 AM

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?