}
}
+ClangTidyOptions ClangTidyModule::getModuleOptions() {
+ return ClangTidyOptions();
+}
+
} // namespace tidy
} // namespace clang
/// \brief Implement this function in order to register all \c CheckFactories
/// belonging to this module.
virtual void addCheckFactories(ClangTidyCheckFactories &CheckFactories) = 0;
+
+ /// \brief Gets default options for checks defined in this module.
+ virtual ClangTidyOptions getModuleOptions();
};
} // end namespace tidy
//===----------------------------------------------------------------------===//
#include "ClangTidyOptions.h"
+#include "ClangTidyModuleRegistry.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Errc.h"
namespace clang {
namespace tidy {
+ClangTidyOptions ClangTidyOptions::getDefaults() {
+ ClangTidyOptions Options;
+ Options.Checks = "";
+ Options.HeaderFilterRegex = "";
+ Options.AnalyzeTemporaryDtors = false;
+ Options.User = llvm::None;
+ for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
+ E = ClangTidyModuleRegistry::end();
+ I != E; ++I)
+ Options = Options.mergeWith(I->instantiate()->getModuleOptions());
+ return Options;
+}
+
ClangTidyOptions
ClangTidyOptions::mergeWith(const ClangTidyOptions &Other) const {
ClangTidyOptions Result = *this;
/// \brief These options are used for all settings that haven't been
/// overridden by the \c OptionsProvider.
///
- /// Allow no checks and no headers by default.
- static ClangTidyOptions getDefaults() {
- ClangTidyOptions Options;
- Options.Checks = "";
- Options.HeaderFilterRegex = "";
- Options.AnalyzeTemporaryDtors = false;
- Options.User = llvm::None;
- return Options;
- }
+ /// Allow no checks and no headers by default. This method initializes
+ /// check-specific options by calling \c ClangTidyModule::getModuleOptions()
+ /// of each registered \c ClangTidyModule.
+ static ClangTidyOptions getDefaults();
/// \brief Creates a new \c ClangTidyOptions instance combined from all fields
/// of this instance overridden by the fields of \p Other that have a value.
#include "TodoCommentCheck.h"
#include "UnnamedNamespaceInHeaderCheck.h"
#include "UsingNamespaceDirectiveCheck.h"
+#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/NamespaceCommentCheck.h"
using namespace clang::ast_matchers;
"google-readability-todo");
CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
"google-readability-namespace-comments");
+ CheckFactories.registerCheck<readability::BracesAroundStatementsCheck>(
+ "google-readability-braces-around-statements");
+ }
+
+ ClangTidyOptions getModuleOptions() override {
+ ClangTidyOptions Options;
+ auto &Opts = Options.CheckOptions;
+ Opts["google-readability-braces-around-statements.ShortStatementLines"] =
+ "1";
+ Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "1";
+ Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
+ return Options;
}
};
"namespace( +([a-zA-Z0-9_]+))? *(\\*/)?$",
llvm::Regex::IgnoreCase),
ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
- SpacesBeforeComments(Options.get("SpacesBeforeComments",
- Name.startswith("google") ? 2u : 1u)) {}
+ SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines);
--- /dev/null
+// RUN: clang-tidy -checks='-*,google*' -config='{}' -dump-config - -- | FileCheck %s
+// CHECK: CheckOptions:
+// CHECK: {{- key: *google-readability-braces-around-statements.ShortStatementLines}}
+// CHECK-NEXT: {{value: *'1'}}
+// CHECK: {{- key: *google-readability-namespace-comments.ShortNamespaceLines}}
+// CHECK-NEXT: {{value: *'1'}}
+// CHECK: {{- key: *google-readability-namespace-comments.SpacesBeforeComments}}
+// CHECK-NEXT: {{value: *'2'}}