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

Eugene Zelenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 18:25:44 PST 2018


Eugene.Zelenko added a comment.

Please add new module in docs/clang-tidy/index.rst and mention it in release notes.



================
Comment at: clang-tidy/absl/AbslTidyModule.cpp:14
+#include "StringFindStartswithCheck.h"
+using namespace clang::ast_matchers;
+
----------------
Please separate with empty line.


================
Comment at: clang-tidy/absl/StringFindStartswithCheck.cpp:40
+void StringFindStartswithCheck::check(const MatchFinder::MatchResult &result) {
+  const auto &context = *result.Context;
+  const auto &source = context.getSourceManager();
----------------
Please don't use auto when type could not be deduced from same statement. Same in other places.


================
Comment at: clang-tidy/absl/StringFindStartswithCheck.h:30
+private:
+  std::unique_ptr<clang::tidy::utils::IncludeInserter> include_inserter_;
+};
----------------
Please include <memory>


================
Comment at: docs/ReleaseNotes.rst:63
+
+  Checks whether a string::find result is compared with 0, and suggests
+  replacing with absl::StartsWith.
----------------
string::find -> std::string::find(), absl::StartsWith -> absl::StartsWith(). Please enclose them in ``.


================
Comment at: docs/clang-tidy/checks/absl-string-find-startswith.rst:6
+
+This check triggers on (in)equality comparisons between string.find()
+and zero. Comparisons like this should be replaced with
----------------
Please make first statement same as in release notes and avoid //This check//.


================
Comment at: docs/clang-tidy/checks/absl-string-find-startswith.rst:11
+
+::
+
----------------
Please use .. code-block: c++


================
Comment at: docs/clang-tidy/checks/absl-string-find-startswith.rst:17
+should be replaced with
+``if (absl::StartsWith(s, "Hello World")) { /* do something */ };``
+
----------------
Please use .. code-block: c++


================
Comment at: docs/clang-tidy/checks/absl-string-find-startswith.rst:18
+``if (absl::StartsWith(s, "Hello World")) { /* do something */ };``
+
----------------
Is there any online documentation about such usage? If so please refer to in at. See other guidelines as example.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43847





More information about the cfe-commits mailing list