Skip to content

Conversation

@AlanRosenthal
Copy link

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): comment were supported.
After this PR, TODO: info - comment are also supported.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

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
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

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.

@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2024

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Alan Rosenthal (AlanRosenthal)

Changes

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): comment were supported.
After this PR, TODO: info - comment are also supported.


Full diff: https://github.com/llvm/llvm-project/pull/104868.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp (+16-6)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp (+4)
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. 
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.
@AlanRosenthal AlanRosenthal requested a review from 5chmidti August 29, 2024 17:12
Copy link
Contributor

@5chmidti 5chmidti left a 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

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment