carlosgalvezp updated this revision to Diff 377551.
carlosgalvezp added a comment.

Fixed comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111208/new/

https://reviews.llvm.org/D111208

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
@@ -46,6 +46,17 @@
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 9 warnings (9 NOLINT)
+// NOLINTNEXTLINE(google*)
+class I1 { I1(int i); };
+
+// NOLINTNEXTLINE(google*,-google*)
+class I2 { I2(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+// NOLINTNEXTLINE(*,-google*)
+class I3 { I3(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+// CHECK-MESSAGES: Suppressed 10 warnings (10 NOLINT)
 
 // RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -119,4 +119,18 @@
 
 MACRO_NO_LINT_INSIDE_MACRO
 
-// CHECK-MESSAGES: Suppressed 18 warnings (18 NOLINT).
+// NOLINTBEGIN(google*)
+class C13 { C13(int i); };
+// NOLINTEND(google*)
+
+// NOLINTBEGIN(google*,-google*)
+class C14 { C14(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: single-argument constructors must be marked explicit
+// NOLINTEND(google*,-google*)
+
+// NOLINTBEGIN(*,-google*)
+class C15 { C15(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: single-argument constructors must be marked explicit
+// NOLINTEND(*,-google*)
+
+// CHECK-MESSAGES: Suppressed 19 warnings (19 NOLINT).
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
@@ -51,4 +51,16 @@
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
-// CHECK-MESSAGES: Suppressed 13 warnings (13 NOLINT)
+class D1 { D1(int x); }; // NOLINT(google*)
+class D2 { D2(int x); }; // NOLINT(*explicit-constructor)
+class D3 { D3(int x); }; // NOLINT(*explicit*)
+
+class D4 { D4(int x); }; // NOLINT(google*,-google*)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+class D5 { D5(int x); }; // NOLINT(google*,-google*,google*)
+
+class D6 { D6(int x); }; // NOLINT(*,-google*)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+// CHECK-MESSAGES: Suppressed 17 warnings (17 NOLINT)
Index: clang-tools-extra/docs/clang-tidy/index.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -173,11 +173,11 @@
                                      errors were found. If compiler errors have
                                      attached fix-its, clang-tidy will apply them as
                                      well.
-    --fix-notes                    - 
-                                     If a warning has no fix, but a single fix can 
-                                     be found through an associated diagnostic note, 
-                                     apply the fix. 
-                                     Specifying this flag will implicitly enable the 
+    --fix-notes                    -
+                                     If a warning has no fix, but a single fix can
+                                     be found through an associated diagnostic note,
+                                     apply the fix.
+                                     Specifying this flag will implicitly enable the
                                      '--fix' flag.
     --format-style=<string>        -
                                      Style for formatting code around applied fixes:
@@ -308,7 +308,10 @@
 comments).
 
 All comments can be followed by an optional list of check names in parentheses
-(see below for the formal syntax).
+(see below for the formal syntax). The list of check names supports globbing,
+with the same format and semantics as for enabling checks. Note that adding
+a dash, e.g. `NOLINT(-check-name)`, is a double negation ("do *not* suppress
+`check-name`"), so the warning is not expected to be suppressed.
 
 For example:
 
@@ -333,6 +336,15 @@
     Foo(short param);
     Foo(long param);
     // NOLINTEND(google-explicit-constructor, google-runtime-int)
+
+    // Silence all warnings from the "google" module
+    Foo(bool param);  // NOLINT(google*)
+
+    // Silence all warnings, *except* the ones from the "google" module
+    Foo(bool param);  // NOLINT(*,-google*)
+
+    // No warnings are suppressed, due to double negation
+    Foo(bool param);  // NOLINT(-google*)
   };
 
 The formal syntax of ``NOLINT``, ``NOLINTNEXTLINE``, and ``NOLINTBEGIN`` ...
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@
 Improvements to clang-tidy
 --------------------------
 
+- Added support for globbing in `NOLINT*` expressions, to simplify suppressing
+  multiple warnings in the same line.
+
 - Added support for `NOLINTBEGIN` ... `NOLINTEND` comments to suppress
   Clang-Tidy warnings over multiple lines.
 
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -345,18 +345,12 @@
     if (BracketEndIndex != StringRef::npos) {
       StringRef ChecksStr =
           Line.substr(BracketIndex, BracketEndIndex - BracketIndex);
-      // Allow disabling all the checks with "*".
-      if (ChecksStr != "*") {
-        // Allow specifying a few check names, delimited with comma.
-        SmallVector<StringRef, 1> Checks;
-        ChecksStr.split(Checks, ',', -1, false);
-        llvm::transform(Checks, Checks.begin(),
-                        [](StringRef S) { return S.trim(); });
-        if (llvm::find(Checks, CheckName) == Checks.end())
-          return false;
-        if (SuppressionIsSpecific)
-          *SuppressionIsSpecific = true;
-      }
+      // Allow specifying a few checks with a glob expression.
+      GlobList Globs(ChecksStr);
+      if (!Globs.contains(CheckName))
+        return false;
+      if (SuppressionIsSpecific)
+        *SuppressionIsSpecific = true;
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to