[clang-tools-extra] r261431 - [clang-tidy] Describe modules, link to LLVM development docs, other minor updates

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 20 03:42:14 PST 2016


Author: alexfh
Date: Sat Feb 20 05:42:13 2016
New Revision: 261431

URL: http://llvm.org/viewvc/llvm-project?rev=261431&view=rev
Log:
[clang-tidy] Describe modules, link to LLVM development docs, other minor updates

Modified:
    clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=261431&r1=261430&r2=261431&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Sat Feb 20 05:42:13 2016
@@ -328,10 +328,38 @@ Writing a clang-tidy Check
 
 So you have an idea of a useful check for :program:`clang-tidy`.
 
-You need to decide which module the check belongs to. If the check verifies
-conformance of the code to a certain coding style, it probably deserves a
-separate module and a directory in ``clang-tidy/`` (there are LLVM and Google
-modules already).
+First, if you're not familiar with LLVM development, read through the `Getting
+Started with LLVM`_ document for instructions on setting up your workflow and
+the `LLVM Coding Standards`_ document to familiarize yourself with the coding
+style used in the project. For code reviews we mostly use `LLVM Phabricator`_.
+
+.. _Getting Started with LLVM: http://llvm.org/docs/GettingStarted.html
+.. _LLVM Coding Standards: http://llvm.org/docs/CodingStandards.html
+.. _LLVM Phabricator: http://llvm.org/docs/Phabricator.html
+
+
+Next, you need to decide which module the check belongs to. If the check
+verifies conformance of the code to a certain coding style, it probably deserves
+a separate module and a directory in ``clang-tidy/``. There are already modules
+implementing checks related to:
+
+* `C++ Core Guidelines
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/>`_
+* `CERT Secure Coding Standards
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/cert/>`_
+* `Google Style Guide
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/google/>`_
+* `LLVM Style
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/llvm/>`_
+* `modernizing C/C++ code
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/modernize/>`_
+* potential `performance problems
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/performance/>`_
+* various `readability issues
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/readability/>`_
+* and `miscellaneous checks
+  <http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/misc/>`_
+  that we couldn't find a better category for.
 
 After choosing the module, you need to create a class for your check:
 
@@ -341,13 +369,21 @@ After choosing the module, you need to c
 
   namespace clang {
   namespace tidy {
+  namespace some_module {
 
   class MyCheck : public ClangTidyCheck {
+  public:
+    MyCheck(StringRef Name, ClangTidyContext *Context)
+        : ClangTidyCheck(Name, Context) {}
   };
 
+  } // namespace some_module
   } // namespace tidy
   } // namespace clang
 
+Constructor of the check receives the ``Name`` and ``Context`` parameters, and
+must forward them to the ``ClangTidyCheck`` constructor.
+
 Next, you need to decide whether it should operate on the preprocessor level or
 on the AST level. Let's imagine that we need to work with the AST in our check.
 In this case we need to override two methods:
@@ -363,9 +399,6 @@ In this case we need to override two met
     void check(ast_matchers::MatchFinder::MatchResult &Result) override;
   };
 
-Constructor of the check receives the ``Name`` and ``Context`` parameters, and
-must forward them to the ``ClangTidyCheck`` constructor.
-
 In the ``registerMatchers`` method we create an AST Matcher (see `AST Matchers`_
 for more information) that will find the pattern in the AST that we want to
 inspect. The results of the matching are passed to the ``check`` method, which
@@ -380,8 +413,7 @@ can further inspect them and report diag
   }
 
   void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-    const CXXConstructorDecl *Ctor =
-        Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
+    const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
     // Do not be confused: isExplicit means 'explicit' keyword is present,
     // isImplicit means that it's a compiler-generated constructor.
     if (Ctor->isOutOfLine() || Ctor->isExplicit() || Ctor->isImplicit())
@@ -394,7 +426,10 @@ can further inspect them and report diag
   }
 
 (The full code for this check resides in
-``clang-tidy/google/ExplicitConstructorCheck.{h,cpp}``).
+`clang-tidy/google/ExplicitConstructorCheck.h
+<http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.h>`_
+and `clang-tidy/google/ExplicitConstructorCheck.cpp
+<http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp>`_).
 
 
 Registering your Check
@@ -531,7 +566,7 @@ Running clang-tidy on LLVM
 --------------------------
 
 To test a check it's best to try it out on a larger code base. LLVM and Clang
-are the natural targets as you already have the source around. The most
+are the natural targets as you already have the source code around. The most
 convenient way to run :program:`clang-tidy` is with a compile command database;
 CMake can automatically generate one, for a description of how to enable it see
 `How To Setup Tooling For LLVM`_. Once ``compile_commands.json`` is in place and




More information about the cfe-commits mailing list