[PATCH] Added a naive NOLINT implementation.
Alexander Kornienko
alexfh at google.com
Thu Feb 27 09:28:10 PST 2014
Hi klimek,
Added a naive NOLINT implementation. It doesn't care about specific
linter categories, just the "// NOLINT" on the same line as a diagnostic.
http://llvm-reviews.chandlerc.com/D2896
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,16 @@
DiagnosticBuilder ClangTidyContext::diag(
StringRef CheckName, SourceLocation Loc, StringRef Description,
- DiagnosticIDs::Level Level /* = DiagnosticsEngine::Warning*/) {
+ DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
+ 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.1.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140227/5668526e/attachment.bin>
More information about the cfe-commits
mailing list