[PATCH] D43847: [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 5 07:45:54 PST 2018


hokein added a comment.

In https://reviews.llvm.org/D43847#1025846, @Eugene.Zelenko wrote:

> In https://reviews.llvm.org/D43847#1025833, @niko wrote:
>
> > Thanks everyone for your comments! I renamed the namespace and filenames to 'abseil'.
> >
> > @Eugene.Zelenko, definitely interested in extending this to a C++20 modernize check and adding `absl::EndsWith()` support,  would it be OK though to do this in a later patch?
>
>
> I think will be better to do this now, since you'll need to create base class and specializations for Abseil and C++17.


I'm fine with the current status. We could polish it in a follow-up patch. Let's not put too much on this patch.



================
Comment at: clang-tidy/abseil/StringFindStartswithCheck.cpp:27
+      StringLikeClasses(utils::options::parseStringList(
+          Options.get("StringLikeClasses", "std::basic_string"))),
+      IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
----------------
Use fully-qualified name `::std::basic_string`.


================
Comment at: docs/clang-tidy/checks/abseil-string-find-startswith.rst:4
+abseil-string-find-startswith
+==========================================
+
----------------
nit: this line should align with the title.


================
Comment at: test/clang-tidy/abseil-string-find-startswith.cpp:30
+  s.find(s) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of find() == 0 [abseil-string-find-startswith]
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}}
----------------
nit: you don't have to specify the full message every line (except the first line), so here and below use  `// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith ` is sufficient.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43847





More information about the cfe-commits mailing list