GoogleTidyModule.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //===--- GoogleTidyModule.cpp - clang-tidy --------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "../ClangTidy.h"
  9. #include "../ClangTidyModule.h"
  10. #include "../ClangTidyModuleRegistry.h"
  11. #include "../readability/BracesAroundStatementsCheck.h"
  12. #include "../readability/FunctionSizeCheck.h"
  13. #include "../readability/NamespaceCommentCheck.h"
  14. #include "AvoidCStyleCastsCheck.h"
  15. #include "AvoidNSObjectNewCheck.h"
  16. #include "AvoidThrowingObjCExceptionCheck.h"
  17. #include "AvoidUnderscoreInGoogletestNameCheck.h"
  18. #include "DefaultArgumentsCheck.h"
  19. #include "ExplicitConstructorCheck.h"
  20. #include "ExplicitMakePairCheck.h"
  21. #include "FunctionNamingCheck.h"
  22. #include "GlobalNamesInHeadersCheck.h"
  23. #include "GlobalVariableDeclarationCheck.h"
  24. #include "IntegerTypesCheck.h"
  25. #include "OverloadedUnaryAndCheck.h"
  26. #include "TodoCommentCheck.h"
  27. #include "UnnamedNamespaceInHeaderCheck.h"
  28. #include "UpgradeGoogletestCaseCheck.h"
  29. #include "UsingNamespaceDirectiveCheck.h"
  30. using namespace clang::ast_matchers;
  31. namespace clang::tidy {
  32. namespace google {
  33. class GoogleModule : public ClangTidyModule {
  34. public:
  35. void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
  36. CheckFactories.registerCheck<build::ExplicitMakePairCheck>(
  37. "google-build-explicit-make-pair");
  38. CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>(
  39. "google-build-namespaces");
  40. CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>(
  41. "google-build-using-namespace");
  42. CheckFactories.registerCheck<DefaultArgumentsCheck>(
  43. "google-default-arguments");
  44. CheckFactories.registerCheck<ExplicitConstructorCheck>(
  45. "google-explicit-constructor");
  46. CheckFactories.registerCheck<readability::GlobalNamesInHeadersCheck>(
  47. "google-global-names-in-headers");
  48. CheckFactories.registerCheck<objc::AvoidNSObjectNewCheck>(
  49. "google-objc-avoid-nsobject-new");
  50. CheckFactories.registerCheck<objc::AvoidThrowingObjCExceptionCheck>(
  51. "google-objc-avoid-throwing-exception");
  52. CheckFactories.registerCheck<objc::FunctionNamingCheck>(
  53. "google-objc-function-naming");
  54. CheckFactories.registerCheck<objc::GlobalVariableDeclarationCheck>(
  55. "google-objc-global-variable-declaration");
  56. CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
  57. "google-runtime-int");
  58. CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
  59. "google-runtime-operator");
  60. CheckFactories
  61. .registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>(
  62. "google-readability-avoid-underscore-in-googletest-name");
  63. CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
  64. "google-readability-casting");
  65. CheckFactories.registerCheck<readability::TodoCommentCheck>(
  66. "google-readability-todo");
  67. CheckFactories
  68. .registerCheck<clang::tidy::readability::BracesAroundStatementsCheck>(
  69. "google-readability-braces-around-statements");
  70. CheckFactories.registerCheck<clang::tidy::readability::FunctionSizeCheck>(
  71. "google-readability-function-size");
  72. CheckFactories
  73. .registerCheck<clang::tidy::readability::NamespaceCommentCheck>(
  74. "google-readability-namespace-comments");
  75. CheckFactories.registerCheck<UpgradeGoogletestCaseCheck>(
  76. "google-upgrade-googletest-case");
  77. }
  78. ClangTidyOptions getModuleOptions() override {
  79. ClangTidyOptions Options;
  80. auto &Opts = Options.CheckOptions;
  81. Opts["google-readability-braces-around-statements.ShortStatementLines"] =
  82. "1";
  83. Opts["google-readability-function-size.StatementThreshold"] = "800";
  84. Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10";
  85. Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
  86. return Options;
  87. }
  88. };
  89. // Register the GoogleTidyModule using this statically initialized variable.
  90. static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
  91. "Adds Google lint checks.");
  92. } // namespace google
  93. // This anchor is used to force the linker to link in the generated object file
  94. // and thus register the GoogleModule.
  95. volatile int GoogleModuleAnchorSource = 0;
  96. } // namespace clang::tidy