From 6f67bcbb93bda6cf0654a74721de97a3adc1605b Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 23 Nov 2017 17:02:48 +0000 Subject: [PATCH] [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-comment Summary: + manually convert the unit test to lit test. Reviewers: hokein Reviewed By: hokein Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40392 llvm-svn: 318926 --- .../{misc => bugprone}/ArgumentCommentCheck.cpp | 4 +- .../{misc => bugprone}/ArgumentCommentCheck.h | 4 +- .../clang-tidy/bugprone/BugproneTidyModule.cpp | 3 ++ .../clang-tidy/bugprone/CMakeLists.txt | 1 + clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 1 - .../clang-tidy/misc/MiscTidyModule.cpp | 2 - clang-tools-extra/docs/ReleaseNotes.rst | 3 ++ ...t-comment.rst => bugprone-argument-comment.rst} | 6 +-- clang-tools-extra/docs/clang-tidy/checks/list.rst | 2 +- ...ock.cpp => bugprone-argument-comment-gmock.cpp} | 2 +- ...ct.cpp => bugprone-argument-comment-strict.cpp} | 2 +- ...t-comment.cpp => bugprone-argument-comment.cpp} | 46 +++++++++++++++++++--- .../unittests/clang-tidy/CMakeLists.txt | 2 - .../unittests/clang-tidy/MiscModuleTest.cpp | 39 ------------------ 14 files changed, 57 insertions(+), 60 deletions(-) rename clang-tools-extra/clang-tidy/{misc => bugprone}/ArgumentCommentCheck.cpp (99%) rename clang-tools-extra/clang-tidy/{misc => bugprone}/ArgumentCommentCheck.h (97%) rename clang-tools-extra/docs/clang-tidy/checks/{misc-argument-comment.rst => bugprone-argument-comment.rst} (85%) rename clang-tools-extra/test/clang-tidy/{misc-argument-comment-gmock.cpp => bugprone-argument-comment-gmock.cpp} (98%) rename clang-tools-extra/test/clang-tidy/{misc-argument-comment-strict.cpp => bugprone-argument-comment-strict.cpp} (93%) rename clang-tools-extra/test/clang-tidy/{misc-argument-comment.cpp => bugprone-argument-comment.cpp} (53%) delete mode 100644 clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp similarity index 99% rename from clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp rename to clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp index d7ac9f3..a8da703 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp @@ -18,7 +18,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace bugprone { ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context) @@ -303,6 +303,6 @@ void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) { } } -} // namespace misc +} // namespace bugprone } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h similarity index 97% rename from clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h rename to clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h index 50dda2b..050780d 100644 --- a/clang-tools-extra/clang-tidy/misc/ArgumentCommentCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h @@ -15,7 +15,7 @@ namespace clang { namespace tidy { -namespace misc { +namespace bugprone { /// Checks that argument comments match parameter names. /// @@ -48,7 +48,7 @@ private: llvm::ArrayRef Args); }; -} // namespace misc +} // namespace bugprone } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 1719500..0506c0e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -10,6 +10,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "ArgumentCommentCheck.h" #include "CopyConstructorInitCheck.h" #include "IntegerDivisionCheck.h" #include "MisplacedOperatorInStrlenInAllocCheck.h" @@ -24,6 +25,8 @@ namespace bugprone { class BugproneModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "bugprone-argument-comment"); CheckFactories.registerCheck( "bugprone-copy-constructor-init"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index db724ea..0ee554c 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS support) add_clang_library(clangTidyBugproneModule + ArgumentCommentCheck.cpp BugproneTidyModule.cpp CopyConstructorInitCheck.cpp IntegerDivisionCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index b67b4f7..c1009ba 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -1,7 +1,6 @@ set(LLVM_LINK_COMPONENTS support) add_clang_library(clangTidyMiscModule - ArgumentCommentCheck.cpp AssertSideEffectCheck.cpp ForwardingReferenceOverloadCheck.cpp LambdaFunctionNameCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 8dab93e..11b946f 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -10,7 +10,6 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "ArgumentCommentCheck.h" #include "AssertSideEffectCheck.h" #include "BoolPointerImplicitConversionCheck.h" #include "DanglingHandleCheck.h" @@ -63,7 +62,6 @@ namespace misc { class MiscModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck("misc-argument-comment"); CheckFactories.registerCheck( "misc-assert-side-effect"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6032414..f2bbb57 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -57,6 +57,9 @@ The improvements are... Improvements to clang-tidy -------------------------- +- The 'misc-argument-comment' check was renamed to `bugprone-argument-comment + `_ + - The 'misc-string-constructor' check was renamed to `bugprone-string-constructor `_ diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-argument-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone-argument-comment.rst similarity index 85% rename from clang-tools-extra/docs/clang-tidy/checks/misc-argument-comment.rst rename to clang-tools-extra/docs/clang-tidy/checks/bugprone-argument-comment.rst index b4101c2..5f7e5f0 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc-argument-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone-argument-comment.rst @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-argument-comment +.. title:: clang-tidy - bugprone-argument-comment -misc-argument-comment -===================== +bugprone-argument-comment +========================= Checks that argument comments match parameter names. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 5d71474..c389e54 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -17,6 +17,7 @@ Clang-Tidy Checks android-cloexec-open android-cloexec-socket boost-use-to-string + bugprone-argument-comment bugprone-copy-constructor-init bugprone-integer-division bugprone-misplaced-operator-in-strlen-in-alloc @@ -105,7 +106,6 @@ Clang-Tidy Checks llvm-include-order llvm-namespace-comment llvm-twine-local - misc-argument-comment misc-assert-side-effect misc-bool-pointer-implicit-conversion misc-dangling-handle diff --git a/clang-tools-extra/test/clang-tidy/misc-argument-comment-gmock.cpp b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-gmock.cpp similarity index 98% rename from clang-tools-extra/test/clang-tidy/misc-argument-comment-gmock.cpp rename to clang-tools-extra/test/clang-tidy/bugprone-argument-comment-gmock.cpp index 56a7b14..e79395e 100644 --- a/clang-tools-extra/test/clang-tidy/misc-argument-comment-gmock.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-gmock.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-argument-comment %t +// RUN: %check_clang_tidy %s bugprone-argument-comment %t namespace testing { namespace internal { diff --git a/clang-tools-extra/test/clang-tidy/misc-argument-comment-strict.cpp b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-strict.cpp similarity index 93% rename from clang-tools-extra/test/clang-tidy/misc-argument-comment-strict.cpp rename to clang-tools-extra/test/clang-tidy/bugprone-argument-comment-strict.cpp index d37b869..0e06a4c 100644 --- a/clang-tools-extra/test/clang-tidy/misc-argument-comment-strict.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment-strict.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-argument-comment %t -- \ +// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- \ // RUN: -config="{CheckOptions: [{key: StrictMode, value: 1}]}" -- void f(int _with_underscores_); diff --git a/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment.cpp similarity index 53% rename from clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp rename to clang-tools-extra/test/clang-tidy/bugprone-argument-comment.cpp index e20ba10..6452791 100644 --- a/clang-tools-extra/test/clang-tidy/misc-argument-comment.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-argument-comment.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-argument-comment %t +// RUN: %check_clang_tidy %s bugprone-argument-comment %t // FIXME: clang-tidy should provide a -verify mode to make writing these checks // easier and more accurate. @@ -14,9 +14,16 @@ void g() { f(/*y=*/0, /*z=*/0); // CHECK-FIXES: {{^}} f(/*y=*/0, /*z=*/0); + f(/*x=*/1, /*y=*/1); + ffff(0 /*aaaa=*/, /*bbbb*/ 0); // Unsupported formats. } +struct C { + C(int x, int y); +}; +C c(/*x=*/0, /*y=*/0); + struct Closure {}; template @@ -45,11 +52,38 @@ void templates() { #define FALSE 0 void qqq(bool aaa); -void f() { qqq(/*bbb=*/FALSE); } -// CHECK-MESSAGES: [[@LINE-1]]:16: warning: argument name 'bbb' in comment does not match parameter name 'aaa' -// CHECK-FIXES: void f() { qqq(/*bbb=*/FALSE); } +void f2() { qqq(/*bbb=*/FALSE); } +// CHECK-MESSAGES: [[@LINE-1]]:17: warning: argument name 'bbb' in comment does not match parameter name 'aaa' +// CHECK-FIXES: void f2() { qqq(/*bbb=*/FALSE); } -void f(bool _with_underscores_); +void f3(bool _with_underscores_); void ignores_underscores() { - f(/*With_Underscores=*/false); + f3(/*With_Underscores=*/false); +} + +namespace ThisEditDistanceAboveThreshold { +void f4(int xxx); +void g() { f4(/*xyz=*/0); } +// CHECK-MESSAGES: [[@LINE-1]]:15: warning: argument name 'xyz' in comment does not match parameter name 'xxx' +// CHECK-FIXES: void g() { f4(/*xyz=*/0); } +} + +namespace OtherEditDistanceAboveThreshold { +void f5(int xxx, int yyy); +void g() { f5(/*Zxx=*/0, 0); } +// CHECK-MESSAGES: [[@LINE-1]]:15: warning: argument name 'Zxx' in comment does not match parameter name 'xxx' +// CHECK-FIXES: void g() { f5(/*xxx=*/0, 0); } +struct C2 { + C2(int xxx, int yyy); +}; +C2 c2(/*Zxx=*/0, 0); +// CHECK-MESSAGES: [[@LINE-1]]:7: warning: argument name 'Zxx' in comment does not match parameter name 'xxx' +// CHECK-FIXES: C2 c2(/*xxx=*/0, 0); +} + +namespace OtherEditDistanceBelowThreshold { +void f6(int xxx, int yyy); +void g() { f6(/*xxy=*/0, 0); } +// CHECK-MESSAGES: [[@LINE-1]]:15: warning: argument name 'xxy' in comment does not match parameter name 'xxx' +// CHECK-FIXES: void g() { f6(/*xxy=*/0, 0); } } diff --git a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt index 0973ee1..c284fd7 100644 --- a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt @@ -12,7 +12,6 @@ add_extra_unittest(ClangTidyTests IncludeInserterTest.cpp GoogleModuleTest.cpp LLVMModuleTest.cpp - MiscModuleTest.cpp NamespaceAliaserTest.cpp ObjCModuleTest.cpp OverlappingReplacementsTest.cpp @@ -29,7 +28,6 @@ target_link_libraries(ClangTidyTests clangTidyAndroidModule clangTidyGoogleModule clangTidyLLVMModule - clangTidyMiscModule clangTidyObjCModule clangTidyReadabilityModule clangTidyUtils diff --git a/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp deleted file mode 100644 index a3f00b8..0000000 --- a/clang-tools-extra/unittests/clang-tidy/MiscModuleTest.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "ClangTidyTest.h" -#include "misc/ArgumentCommentCheck.h" -#include "gtest/gtest.h" - -namespace clang { -namespace tidy { -namespace test { - -using misc::ArgumentCommentCheck; - -TEST(ArgumentCommentCheckTest, CorrectComments) { - EXPECT_NO_CHANGES(ArgumentCommentCheck, - "void f(int x, int y); void g() { f(/*x=*/0, /*y=*/0); }"); - EXPECT_NO_CHANGES(ArgumentCommentCheck, - "struct C { C(int x, int y); }; C c(/*x=*/0, /*y=*/0);"); -} - -TEST(ArgumentCommentCheckTest, ThisEditDistanceAboveThreshold) { - EXPECT_NO_CHANGES(ArgumentCommentCheck, - "void f(int xxx); void g() { f(/*xyz=*/0); }"); -} - -TEST(ArgumentCommentCheckTest, OtherEditDistanceAboveThreshold) { - EXPECT_EQ("void f(int xxx, int yyy); void g() { f(/*xxx=*/0, 0); }", - runCheckOnCode( - "void f(int xxx, int yyy); void g() { f(/*Zxx=*/0, 0); }")); - EXPECT_EQ("struct C { C(int xxx, int yyy); }; C c(/*xxx=*/0, 0);", - runCheckOnCode( - "struct C { C(int xxx, int yyy); }; C c(/*Zxx=*/0, 0);")); -} - -TEST(ArgumentCommentCheckTest, OtherEditDistanceBelowThreshold) { - EXPECT_NO_CHANGES(ArgumentCommentCheck, - "void f(int xxx, int yyy); void g() { f(/*xxy=*/0, 0); }"); -} - -} // namespace test -} // namespace tidy -} // namespace clang -- 2.7.4