llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tidy Author: Quentin Khan (qukhan) <details> <summary>Changes</summary> The [Google style guide] now allows (and recommends) writing TODOs with the following format: ```cpp // TODO: bug reference - details about what needs to be done. ``` With this change the checker accepts the new style and suggests in in the fix-it hint. The previous style is still accepted. [Google style guide]: https://google.github.io/styleguide/cppguide.html#TODO_Comments --- Full diff: https://github.com/llvm/llvm-project/pull/165565.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp (+18-9) - (modified) clang-tools-extra/test/clang-tidy/checkers/google/readability-todo.cpp (+18-4) ``````````diff diff --git a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp index 8554870287c81..131d0cd14dda9 100644 --- a/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp @@ -17,28 +17,37 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { public: TodoCommentHandler(TodoCommentCheck &Check, std::optional<std::string> User) : Check(Check), User(User ? *User : "unknown"), - TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {} + TodoMatch("^// *TODO *((\\((.*)\\))?:?( )?|: *(.*) *- *)?(.*)$") {} bool HandleComment(Preprocessor &PP, SourceRange Range) override { StringRef Text = Lexer::getSourceText(CharSourceRange::getCharRange(Range), PP.getSourceManager(), PP.getLangOpts()); - SmallVector<StringRef, 4> Matches; + SmallVector<StringRef, 7> Matches; if (!TodoMatch.match(Text, &Matches)) return false; - StringRef Username = Matches[1]; - StringRef Comment = Matches[3]; + const bool deprecated_style = !Matches[3].empty(); + StringRef Username = deprecated_style ? Matches[5] : Matches[3]; + StringRef Comment = Matches[6]; - if (!Username.empty()) + if (!Username.empty() && (deprecated_style || !Comment.empty())) return false; - std::string NewText = ("// TODO(" + Twine(User) + "): " + Comment).str(); + if (Username.empty()) { + std::string NewText = ("// TODO: " + Twine(User) + " - " + + (Comment.empty() ? "some details" : Comment)) + .str(); + + Check.diag(Range.getBegin(), "missing username/bug in TODO") + << FixItHint::CreateReplacement(CharSourceRange::getCharRange(Range), + NewText); + } + + if (Comment.empty()) + Check.diag(Range.getBegin(), "missing details in TODO"); - Check.diag(Range.getBegin(), "missing username/bug in TODO") - << FixItHint::CreateReplacement(CharSourceRange::getCharRange(Range), - NewText); return false; } 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 6b900aa92150e..5701b30bef395 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 @@ -2,22 +2,36 @@ // TODOfix this1 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO -// CHECK-FIXES: // TODO(some user): fix this1 +// CHECK-FIXES: // TODO: some user - fix this1 // TODO fix this2 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO -// CHECK-FIXES: // TODO(some user): fix this2 +// CHECK-FIXES: // TODO: some user - fix this2 // TODO fix this3 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO -// CHECK-FIXES: // TODO(some user): fix this3 +// CHECK-FIXES: // TODO: some user - fix this3 // TODO: fix this4 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO -// CHECK-FIXES: // TODO(some user): fix this4 +// CHECK-FIXES: // TODO: some user - fix this4 + +// TODO: bug 12345 - +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing details in TODO + +// TODO: a message without a reference +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO +// CHECK-FIXES: // TODO: some user - a message without a reference // TODO(clang)fix this5 +// TODO: foo - shave yaks +// TODO:foo - no space bewteen semicolon and username +// TODO: foo- no space bewteen username and dash +// TODO: foo - extra spaces between semicolon and username +// TODO: foo - extra spaces between username and dash +// TODO: b/12345 - use a b/ prefix +// TODO: bug 12345 - use a space in username/bug reference // TODO(foo):shave yaks // TODO(bar): // TODO(foo): paint bikeshed `````````` </details> https://github.com/llvm/llvm-project/pull/165565 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
