hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

We strip the "[clang-tidy-check]" suffix from the clang-tidy diagnostics, we
should be consistent with the message in FixIt (strip the suffix as well).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63926

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -60,6 +60,10 @@
          arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
 }
 
+MATCHER_P(FixMessage, Message, "") {
+  return arg.Message == Message;
+}
+
 MATCHER_P(EqualToLSPDiag, LSPDiag,
           "LSP diagnostic " + llvm::to_string(LSPDiag)) {
   if (toJSON(arg) != toJSON(LSPDiag)) {
@@ -180,19 +184,17 @@
     #include $deprecated[["assert.h"]]
 
     #define $macrodef[[SQUARE]](X) (X)*(X)
-    int main() {
-      return $doubled[[sizeof]](sizeof(int));
-    }
-    int square() {
+    int $main[[main]]() {
       int y = 4;
       return SQUARE($macroarg[[++]]y);
+      return $doubled[[sizeof]](sizeof(int));
     }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
   TU.HeaderFilename = "assert.h"; // Suppress "not found" error.
   TU.ClangTidyChecks =
       "-*, bugprone-sizeof-expression, bugprone-macro-repeated-side-effects, "
-      "modernize-deprecated-headers";
+      "modernize-deprecated-headers, modernize-use-trailing-return-type";
   EXPECT_THAT(
       TU.build().getDiagnostics(),
       UnorderedElementsAre(
@@ -214,7 +216,15 @@
               WithNote(
                   Diag(Test.range("macrodef"), "macro 'SQUARE' defined 
here"))),
           Diag(Test.range("macroarg"),
-               "multiple unsequenced modifications to 'y'")));
+               "multiple unsequenced modifications to 'y'"),
+          AllOf(
+            Diag(Test.range("main"),
+                 "use a trailing return type for this function"),
+            DiagSource(Diag::ClangTidy),
+            DiagName("modernize-use-trailing-return-type"),
+            // Verify that we don't have "[check-name]" suffix in the message.
+            WithFix(FixMessage("use a trailing return type for this 
function")))
+          ));
 }
 
 TEST(DiagnosticTest, ClangTidySuppressionComment) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -418,6 +418,8 @@
         CleanMessage(Diag.Message);
         for (auto &Note : Diag.Notes)
           CleanMessage(Note.Message);
+        for (auto &Fix : Diag.Fixes)
+          CleanMessage(Fix.Message);
         continue;
       }
     }


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -60,6 +60,10 @@
          arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
 }
 
+MATCHER_P(FixMessage, Message, "") {
+  return arg.Message == Message;
+}
+
 MATCHER_P(EqualToLSPDiag, LSPDiag,
           "LSP diagnostic " + llvm::to_string(LSPDiag)) {
   if (toJSON(arg) != toJSON(LSPDiag)) {
@@ -180,19 +184,17 @@
     #include $deprecated[["assert.h"]]
 
     #define $macrodef[[SQUARE]](X) (X)*(X)
-    int main() {
-      return $doubled[[sizeof]](sizeof(int));
-    }
-    int square() {
+    int $main[[main]]() {
       int y = 4;
       return SQUARE($macroarg[[++]]y);
+      return $doubled[[sizeof]](sizeof(int));
     }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
   TU.HeaderFilename = "assert.h"; // Suppress "not found" error.
   TU.ClangTidyChecks =
       "-*, bugprone-sizeof-expression, bugprone-macro-repeated-side-effects, "
-      "modernize-deprecated-headers";
+      "modernize-deprecated-headers, modernize-use-trailing-return-type";
   EXPECT_THAT(
       TU.build().getDiagnostics(),
       UnorderedElementsAre(
@@ -214,7 +216,15 @@
               WithNote(
                   Diag(Test.range("macrodef"), "macro 'SQUARE' defined here"))),
           Diag(Test.range("macroarg"),
-               "multiple unsequenced modifications to 'y'")));
+               "multiple unsequenced modifications to 'y'"),
+          AllOf(
+            Diag(Test.range("main"),
+                 "use a trailing return type for this function"),
+            DiagSource(Diag::ClangTidy),
+            DiagName("modernize-use-trailing-return-type"),
+            // Verify that we don't have "[check-name]" suffix in the message.
+            WithFix(FixMessage("use a trailing return type for this function")))
+          ));
 }
 
 TEST(DiagnosticTest, ClangTidySuppressionComment) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===================================================================
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -418,6 +418,8 @@
         CleanMessage(Diag.Message);
         for (auto &Note : Diag.Notes)
           CleanMessage(Note.Message);
+        for (auto &Fix : Diag.Fixes)
+          CleanMessage(Fix.Message);
         continue;
       }
     }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D63926: [clangd] Make F... Haojian Wu via Phabricator via cfe-commits

Reply via email to