[PATCH] Added a naive NOLINT implementation.

Alexander Kornienko alexfh at google.com
Thu Feb 27 09:32:07 PST 2014


  Added an assertion.

Hi klimek,

http://llvm-reviews.chandlerc.com/D2896

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2896?vs=7406&id=7407#toc

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  test/clang-tidy/nolint.cpp

Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -39,7 +39,17 @@
 
 DiagnosticBuilder ClangTidyContext::diag(
     StringRef CheckName, SourceLocation Loc, StringRef Description,
-    DiagnosticIDs::Level Level /* = DiagnosticsEngine::Warning*/) {
+    DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
+  assert(Loc.isValid());
+  bool Invalid;
+  const char *CharacterData =
+      DiagEngine->getSourceManager().getCharacterData(Loc, &Invalid);
+  if (!Invalid) {
+    StringRef Line(CharacterData);
+    Line = Line.substr(0, Line.find_first_of("\r\n"));
+    if(Line.find("// NOLINT") != StringRef::npos)
+      Level = DiagnosticIDs::Ignored;
+  }
   unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
       Level, (Description + " [" + CheckName + "]").str());
   if (CheckNamesByDiagnosticID.count(ID) == 0)
Index: test/clang-tidy/nolint.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/nolint.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-tidy -checks=google-explicit-constructor %s -- | FileCheck %s
+
+class A { A(int i); };
+// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]
+
+class B { B(int i); }; // NOLINT
+// CHECK-NOT: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]
+
+class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet)
+// CHECK-NOT: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2896.2.patch
Type: text/x-patch
Size: 1726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140227/9063794b/attachment.bin>


More information about the cfe-commits mailing list