[clang-tidy] Bring order to check registration.
authorAlexander Kornienko <alexfh@google.com>
Sun, 26 Oct 2014 01:41:14 +0000 (01:41 +0000)
committerAlexander Kornienko <alexfh@google.com>
Sun, 26 Oct 2014 01:41:14 +0000 (01:41 +0000)
Summary:
Register readability checks in a separate module. Renamed the checks
and test file names accordingly.

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: curdeius, cfe-commits

Differential Revision: http://reviews.llvm.org/D5936

llvm-svn: 220631

21 files changed:
clang-tools-extra/clang-tidy/google/CMakeLists.txt
clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/test/clang-tidy/google-module.cpp
clang-tools-extra/test/clang-tidy/google-readability-casting.c [moved from clang-tools-extra/test/clang-tidy/avoid-c-style-casts.c with 100% similarity]
clang-tools-extra/test/clang-tidy/google-readability-casting.cpp [moved from clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp with 100% similarity]
clang-tools-extra/test/clang-tidy/misc-use-override.cpp [moved from clang-tools-extra/test/clang-tidy/use-override.cpp with 100% similarity]
clang-tools-extra/test/clang-tidy/readability-braces-around-statements-few-lines.cpp [moved from clang-tools-extra/test/clang-tidy/misc-braces-around-statements-few-lines.cpp with 77% similarity]
clang-tools-extra/test/clang-tidy/readability-braces-around-statements-same-line.cpp [moved from clang-tools-extra/test/clang-tidy/misc-braces-around-statements-same-line.cpp with 82% similarity]
clang-tools-extra/test/clang-tidy/readability-braces-around-statements-single-line.cpp [moved from clang-tools-extra/test/clang-tidy/misc-braces-around-statements-single-line.cpp with 80% similarity]
clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp [moved from clang-tools-extra/test/clang-tidy/misc-braces-around-statements.cpp with 98% similarity]
clang-tools-extra/test/clang-tidy/readability-function-size.cpp [moved from clang-tools-extra/test/clang-tidy/misc-function-size.cpp with 88% similarity]
clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp [moved from clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp with 95% similarity]
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp [moved from clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp with 100% similarity]

index 7b0912d..bbe9b4d 100644 (file)
@@ -20,5 +20,5 @@ add_clang_library(clangTidyGoogleModule
   clangBasic
   clangLex
   clangTidy
-  clangTidyReadability
+  clangTidyReadabilityModule
   )
index 9ff5cae..16ebfe5 100644 (file)
@@ -22,7 +22,9 @@
 #include "UnnamedNamespaceInHeaderCheck.h"
 #include "UsingNamespaceDirectiveCheck.h"
 #include "../readability/BracesAroundStatementsCheck.h"
+#include "../readability/FunctionSize.h"
 #include "../readability/NamespaceCommentCheck.h"
+#include "../readability/RedundantSmartptrGet.h"
 
 using namespace clang::ast_matchers;
 
@@ -54,10 +56,14 @@ public:
         "google-readability-function");
     CheckFactories.registerCheck<readability::TodoCommentCheck>(
         "google-readability-todo");
-    CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
-        "google-readability-namespace-comments");
     CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
         "google-readability-braces-around-statements");
+    CheckFactories.registerCheck<readability::FunctionSizeCheck>(
+        "google-readability-function-size");
+    CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
+        "google-readability-namespace-comments");
+    CheckFactories.registerCheck<readability::RedundantSmartptrGet>(
+        "google-readability-redundant-smartptr-get");
   }
 
   ClangTidyOptions getModuleOptions() override {
@@ -65,6 +71,7 @@ public:
     auto &Opts = Options.CheckOptions;
     Opts["google-readability-braces-around-statements.ShortStatementLines"] =
         "1";
+    Opts["google-readability-function-size.StatementThreshold"] = "800";
     Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "1";
     Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
     return Options;
index 360e930..ce69c05 100644 (file)
@@ -12,7 +12,7 @@ add_clang_library(clangTidyLLVMModule
   clangBasic
   clangLex
   clangTidy
-  clangTidyReadability
+  clangTidyReadabilityModule
   clangTidyUtils
   clangTooling
   )
index abedee9..ef29603 100644 (file)
@@ -15,6 +15,4 @@ add_clang_library(clangTidyMiscModule
   clangBasic
   clangLex
   clangTidy
-  # Some readability checks are currently registered in the misc module.
-  clangTidyReadability
   )
index c2220b6..d4ba1db 100644 (file)
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-// FIXME: Figure out if we want to create a separate module for readability
-// checks instead of registering them here.
-#include "../readability/BracesAroundStatementsCheck.h"
-#include "../readability/FunctionSize.h"
-#include "../readability/RedundantSmartptrGet.h"
 #include "ArgumentCommentCheck.h"
 #include "BoolPointerImplicitConversion.h"
 #include "SwappedArgumentsCheck.h"
@@ -31,12 +26,6 @@ public:
     CheckFactories.registerCheck<ArgumentCommentCheck>("misc-argument-comment");
     CheckFactories.registerCheck<BoolPointerImplicitConversion>(
         "misc-bool-pointer-implicit-conversion");
-    CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
-        "misc-braces-around-statements");
-    CheckFactories.registerCheck<readability::FunctionSizeCheck>(
-        "misc-function-size");
-    CheckFactories.registerCheck<readability::RedundantSmartptrGet>(
-        "misc-redundant-smartptr-get");
     CheckFactories.registerCheck<SwappedArgumentsCheck>(
         "misc-swapped-arguments");
     CheckFactories.registerCheck<UndelegatedConstructorCheck>(
index edbeb1f..cf1248c 100644 (file)
@@ -1,9 +1,10 @@
 set(LLVM_LINK_COMPONENTS support)
 
-add_clang_library(clangTidyReadability
+add_clang_library(clangTidyReadabilityModule
   BracesAroundStatementsCheck.cpp
   FunctionSize.cpp
   NamespaceCommentCheck.cpp
+  ReadabilityTidyModule.cpp
   RedundantSmartptrGet.cpp
 
   LINK_LIBS
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
new file mode 100644 (file)
index 0000000..9e71875
--- /dev/null
@@ -0,0 +1,44 @@
+//===--- ReadabilityTidyModule.cpp - clang-tidy ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "BracesAroundStatementsCheck.h"
+#include "FunctionSize.h"
+#include "RedundantSmartptrGet.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+class ReadabilityModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+    CheckFactories.registerCheck<BracesAroundStatementsCheck>(
+        "readability-braces-around-statements");
+    CheckFactories.registerCheck<FunctionSizeCheck>(
+        "readability-function-size");
+    CheckFactories.registerCheck<RedundantSmartptrGet>(
+        "readability-redundant-smartptr-get");
+  }
+};
+
+} // namespace readability
+
+// Register the MiscTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add<readability::ReadabilityModule>
+X("readability-module", "Adds readability-related checks.");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the MiscModule.
+volatile int ReadabilityModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang
index a4f2085..a20dcb7 100644 (file)
@@ -12,6 +12,7 @@ target_link_libraries(clang-tidy
   clangTidyGoogleModule
   clangTidyLLVMModule
   clangTidyMiscModule
+  clangTidyReadabilityModule
   clangTooling
   )
 
index 72d841e..01de2e0 100644 (file)
@@ -302,6 +302,10 @@ static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource;
 extern volatile int MiscModuleAnchorSource;
 static int MiscModuleAnchorDestination = MiscModuleAnchorSource;
 
+// This anchor is used to force the linker to link the ReadabilityModule.
+extern volatile int ReadabilityModuleAnchorSource;
+static int ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource;
+
 } // namespace tidy
 } // namespace clang
 
index b7be164..b8c5d69 100644 (file)
@@ -2,6 +2,8 @@
 // CHECK: CheckOptions:
 // CHECK: {{- key: *google-readability-braces-around-statements.ShortStatementLines}}
 // CHECK-NEXT: {{value: *'1'}}
+// CHECK: {{- key: *google-readability-function-size.StatementThreshold}}
+// CHECK-NEXT: {{value: *'800'}}
 // CHECK: {{- key: *google-readability-namespace-comments.ShortNamespaceLines}}
 // CHECK-NEXT: {{value: *'1'}}
 // CHECK: {{- key: *google-readability-namespace-comments.SpacesBeforeComments}}
@@ -1,4 +1,4 @@
-// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 4}]}" --
+// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" --
 // REQUIRES: shell
 
 void do_something(const char *) {}
@@ -1,4 +1,4 @@
-// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 1}]}" --
+// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 1}]}" --
 // REQUIRES: shell
 
 void do_something(const char *) {}
@@ -1,4 +1,4 @@
-// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 2}]}" --
+// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" --
 // REQUIRES: shell
 
 void do_something(const char *) {}
@@ -1,4 +1,4 @@
-// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t
+// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t
 // REQUIRES: shell
 
 void do_something(const char *) {}
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: mkdir -p %t
 // RUN: sed 's#// *[A-Z-][A-Z-]*:.*#//#' %s > %t/t.cpp
-// RUN: echo '{ Checks: "-*,misc-function-size", CheckOptions: [{key: misc-function-size.LineThreshold, value: 0}, {key: misc-function-size.StatementThreshold, value: 0}, {key: misc-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy
+// RUN: echo '{ Checks: "-*,readability-function-size", CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy
 // RUN: clang-tidy %t/t.cpp -- -std=c++11 2>&1 | FileCheck %s -implicit-check-not='{{warning:|error:|note:}}'
 
 void foo1() {
@@ -1,4 +1,4 @@
-// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-redundant-smartptr-get %t
+// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-redundant-smartptr-get %t
 // REQUIRES: shell
 
 #define NULL __null
@@ -49,7 +49,7 @@ void Positive() {
   BarPtr u;
   // CHECK-FIXES: BarPtr u;
   BarPtr().get()->Do();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [misc-redundant-smartptr-get]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [readability-redundant-smartptr-get]
   // CHECK-MESSAGES: BarPtr().get()->Do();
   // CHECK-FIXES: BarPtr()->Do();
 
index 6eda4c0..92d5d38 100644 (file)
@@ -9,10 +9,10 @@ include_directories(${CLANG_LINT_SOURCE_DIR})
 add_extra_unittest(ClangTidyTests
   ClangTidyDiagnosticConsumerTest.cpp
   ClangTidyOptionsTest.cpp
-  LLVMModuleTest.cpp
-  ReadabilityChecksTest.cpp
   GoogleModuleTest.cpp
-  MiscModuleTest.cpp)
+  LLVMModuleTest.cpp
+  MiscModuleTest.cpp
+  ReadabilityModuleTest.cpp)
 
 target_link_libraries(ClangTidyTests
   clangAST
@@ -23,7 +23,7 @@ target_link_libraries(ClangTidyTests
   clangTidyGoogleModule
   clangTidyLLVMModule
   clangTidyMiscModule
-  clangTidyReadability
+  clangTidyReadabilityModule
   clangTidyUtils
   clangTooling
   )