This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Replace unrecognized namespace ending comments.
ClosedPublic

Authored by alexfh on Mar 5 2015, 4:19 AM.

Details

Summary

Replace unrecognized namespace ending comments. This will help in particular when a namespace ending comment is mistyped or doesn't fit the regexp for other reason, e.g.:

namespace a {
namespace b {
namespace {
} // anoynmous namespace
} // b
} // namesapce a

Diff Detail

Event Timeline

alexfh updated this revision to Diff 21268.Mar 5 2015, 4:19 AM
alexfh retitled this revision from to [clang-tidy] Add an option to replace unrecognized namespace ending comments..
alexfh updated this object.
alexfh edited the test plan for this revision. (Show Details)
alexfh added a reviewer: djasper.
alexfh added a subscriber: Unknown Object (MLST).
djasper edited edge metadata.Mar 5 2015, 4:32 AM

Why do you need this as an option. Wouldn't it be the right thing to do in almost all cases?

alexfh added a comment.Mar 5 2015, 4:52 AM

Why do you need this as an option. Wouldn't it be the right thing to do in almost all cases?

There can actually be a meaningful comment in this place, and we're going to remove it with this option on. As this is a generic enough check, the way of allowing to configure this behavior seems to be preferred, I think. That doesn't make the code much more compilcated in any case.

I think adding this option is a way of copping out of fixing this correctly.

For now, I'd be fine saying always to overwrite such a comment. Either a project, enforcing such comment, then they won't have a different comment in the same place or they don't. If clang-tidy complains about / overwrites one of your comments, you'll reinstate it at a better location prior to submit.

A next step might be to analyze whether a comment in that place is meant to close the namespace, e.g. by checking whether its content contains at least one of "namespace" or <namespace-name>.

alexfh updated this revision to Diff 21276.Mar 5 2015, 6:48 AM
alexfh edited edge metadata.

Remove unrecognized namespace ending line comments unconditionally.

djasper accepted this revision.Mar 5 2015, 6:49 AM
djasper edited edge metadata.

LG.

This revision is now accepted and ready to land.Mar 5 2015, 6:49 AM
alexfh added a comment.Mar 5 2015, 6:56 AM

I think adding this option is a way of copping out of fixing this correctly.

For now, I'd be fine saying always to overwrite such a comment. Either a project, enforcing such comment, then they won't have a different comment in the same place or they don't. If clang-tidy complains about / overwrites one of your comments, you'll reinstate it at a better location prior to submit.

Frankly, the need for this option was not dictated by a specific request or an observation, rather an assumption that it may be needed. You're probably right that in this rare situation fixing up the change by hand is a proper solution and usually there's a better place for an unrelated comment than where a namespace ending comment should be.

A next step might be to analyze whether a comment in that place is meant to close the namespace, e.g. by checking whether its content contains at least one of "namespace" or <namespace-name>.

It may be not completely trivial to guess the intention, as the problem usually arises when there's a typo (namesapce, anoynmous, etc.). So we'd need to split the comment and look for keywords with a limit on the edit distance or do something similar. This may not worth it.

alexfh retitled this revision from [clang-tidy] Add an option to replace unrecognized namespace ending comments. to [clang-tidy] Replace unrecognized namespace ending comments..Mar 5 2015, 6:57 AM
alexfh updated this object.
alexfh edited edge metadata.
alexfh closed this revision.Mar 5 2015, 6:58 AM