- Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-tidy] Update TODO comment check #104868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
| @llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Alan Rosenthal (AlanRosenthal) ChangesThe doc for google-readability-todo reference lists two styles of TODO comments: Previously, only Full diff: https://github.com/llvm/llvm-project/pull/104868.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index adad54aa24ba99..f5a7b4bfda6b1a 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -9,6 +9,7 @@ #include "TodoCommentCheck.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" +#include <list> #include <optional> namespace clang::tidy::google::readability { @@ -17,21 +18,30 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { public: TodoCommentHandler(TodoCommentCheck &Check, std::optional<std::string> User) : Check(Check), User(User ? *User : "unknown"), - TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {} + TodoMatches{"^// *TODO *(\\(.*\\)): ?(.*)$", "^// TODO: (.*) - (.*)$"} { + } bool HandleComment(Preprocessor &PP, SourceRange Range) override { StringRef Text = Lexer::getSourceText(CharSourceRange::getCharRange(Range), PP.getSourceManager(), PP.getLangOpts()); + bool Found = false; SmallVector<StringRef, 4> Matches; - if (!TodoMatch.match(Text, &Matches)) + for (const std::string &TodoMatch : TodoMatches) { + if (llvm::Regex(TodoMatch).match(Text, &Matches)) { + Found = true; + break; + } + } + if (!Found) { return false; + } - StringRef Username = Matches[1]; - StringRef Comment = Matches[3]; + StringRef Info = Matches[1]; + StringRef Comment = Matches[2]; - if (!Username.empty()) + if (!Info.empty()) return false; std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str(); @@ -45,7 +55,7 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { private: TodoCommentCheck &Check; std::string User; - llvm::Regex TodoMatch; + std::list<std::string> TodoMatches; }; TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp index 6b900aa92150e8..e41f84b31dabb8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp @@ -24,3 +24,7 @@ // TODO(b/12345): find the holy grail // TODO (b/12345): allow spaces before parentheses // TODO(asdf) allow missing semicolon +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. +// TODO(bug 12345678): Update this list after the Foo service is turned down. +// TODO(John): Use a "\*" here for concatenation operator. |
891fe70 to 9415bc9 Compare The doc for google-readability-todo reference: https://google.github.io/styleguide/cppguide.html#TODO_Comments Which lists two styles of TODO comments. Previously, only `TODO(John): comment` were supported. After this PR, `TODO: bug 123 - comment` are also supported.
9415bc9 to 5f84cc4 Compare clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp Outdated Show resolved Hide resolved
5chmidti left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(noticed I had one pending review comment still open)
Please add a release note (see
llvm-project/clang-tools-extra/docs/ReleaseNotes.rst
Lines 104 to 105 in 412e3e3
| Changes in existing checks | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| // TODO (b/12345): allow spaces before parentheses | ||
| // TODO(asdf) allow missing semicolon | ||
| // TODO: b/12345 - solve the collatz conjecture | ||
| // TODO: foo - bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a case for both forms: TODO(foo): bar - baz
The doc for google-readability-todo reference lists two styles of TODO comments:
https://google.github.io/styleguide/cppguide.html#TODO_Comments
Previously, only
TODO(info): commentwere supported.After this PR,
TODO: info - commentare also supported.