Replace /* ... */ single-line comments with // ... comments
| Bugzilla Link | 24467 |
| Version | unspecified |
| OS | Windows NT |
Extended Description
Detect when C-style /.../ block comments are used to create a single-line comment. Replace those block-style comments with // style comments.
Possible false positives:
/* ....\ */
comments could result in a // comment like this:
// ...\
which would escape the newline and be a problem.
Proposed check name: modernize-use-single-line-comments
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Assign the issue to you.
- Fix the issue locally.
- Run the test suite locally.
3.1) Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a
gitcommit - Run
git clang-format HEAD~1to format your changes. - Submit the patch to Phabricator. 6.1) Detailed instructions can be found here
For more instructions on how to submit a patch to LLVM, see our documentation.
If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue.
@llvm/issue-subscribers-good-first-issue
@PiotrZSL can you provide some analysis and points of entry into codebase?
Create new check, call it modernize-use-double-slash-comments, modernize-use-cpp-comment-style or something else.
- Register new comment handler in registerPPCallbacks with:
PP->addCommentHandler - Implement
clang::CommentHandlerinterface - Read current comment by using
StringRef CommentText = Lexer::getSourceText(CharSourceRange::getCharRange(CommentRange), PP.getSourceManager(), PP.getLangOpts()); - Verify if its block comment for example matching against regexp:
"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$"(or implement this in other way) - Add support to exclude some comments that are for example Doxygen comment (regexp) ?
- Add option to detect / remove frames (those
*****or#######) - Generate fixes that would replace current comment with new one.
I would like to take up the issue if nobody is working as this would be a good start for me to begin llvm. So, please correct me if I am wrong. We have to implement a check that converts /* styled comment that is used for single line to // style. While doing that we have to take care of the like Doxygen comment (as @PiotrZSL mentioned) in clang-tidy.
I am new to this project please help me out.
@chaitanyav , Are you still working on it ? I think I can work on it ! @PiotrZSL @EugeneZelenko .
I think that an option called LineThreshold can be very useful for tuning behavior of this check. In some codebases users may not want to replace big chunks of comments from C-style to C++ style since text can lose readability. For example
/*
10 lines of text
10 lines of text
10 lines of text
*/
void foo()
is arguably easier to read than
// 10 lines of text
// 10 lines of text
// 10 lines of text
void foo()
With LineThreshold set to 5 such big chunks will be excluded from checking.
@vbvictor I wouldn't expect this to cause much of a change, since the check requires us to change single-line C-style comments. However, if that is not the case, I think another case to look into would be the use of doxygen style comments, which, irrespective of the LineThreshold, should be excluded from checking. Also, @4m4n-x-B4w4ne if nobody is currently working on this issue, I would like to take it up Thanks!
This is very much a stylistic type of check and I have no objections to the proposed options. For doxygen style comments one can ues the /// form of doxygen comment.
Hi @LegalizeAdulthood @PiotrZSL @EugeneZelenko,
Can you please assign this to me if @4m4n-x-B4w4ne is not working on it anymore?
Thanks
@vbvictor wrote:
I think that an option called LineThreshold can be very useful for tuning behavior of this check.
I will just point out that the original request was for single-line comments, not multi-line comments.
@vbvictor wrote:
I think that an option called LineThreshold can be very useful for tuning behavior of this check.
I will just point out that the original request was for single-line comments, not multi-line comments.
Yeah, so if I'm not wrong only single-line C-like block comments have to be replaced with '//' handling the false positives mentioned above and excluding any comments for doxygen.