clangBasic
clangLex
clangTidy
- clangTidyReadability
+ clangTidyReadabilityModule
)
#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;
"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 {
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;
clangBasic
clangLex
clangTidy
- clangTidyReadability
+ clangTidyReadabilityModule
clangTidyUtils
clangTooling
)
clangBasic
clangLex
clangTidy
- # Some readability checks are currently registered in the misc module.
- clangTidyReadability
)
#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"
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>(
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
--- /dev/null
+//===--- 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
clangTidyGoogleModule
clangTidyLLVMModule
clangTidyMiscModule
+ clangTidyReadabilityModule
clangTooling
)
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
// 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}}
-// 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 *) {}
-// 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 *) {}
-// 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 *) {}
-// 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 *) {}
// 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() {
-// 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
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();
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
clangTidyGoogleModule
clangTidyLLVMModule
clangTidyMiscModule
- clangTidyReadability
+ clangTidyReadabilityModule
clangTidyUtils
clangTooling
)