[clang-tools-extra] r202452 - Added a naive NOLINT implementation.
Alexander Kornienko
alexfh at google.com
Thu Feb 27 16:27:51 PST 2014
Author: alexfh
Date: Thu Feb 27 18:27:50 2014
New Revision: 202452
URL: http://llvm.org/viewvc/llvm-project?rev=202452&view=rev
Log:
Added a naive NOLINT implementation.
Summary:
Added a naive NOLINT implementation. It doesn't care about specific
linter categories, just the "// NOLINT" on the same line as a diagnostic.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D2896
Added:
clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=202452&r1=202451&r2=202452&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Thu Feb 27 18:27:50 2014
@@ -39,7 +39,20 @@ ClangTidyError::ClangTidyError(StringRef
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) {
+ const char *P = CharacterData;
+ while (*P != '\0' && *P != '\r' && *P != '\n')
+ ++P;
+ StringRef RestOfLine(CharacterData, P - CharacterData + 1);
+ // FIXME: Handle /\bNOLINT\b(\([^)]*\))?/ as cpplint.py does.
+ if (RestOfLine.find("NOLINT") != StringRef::npos)
+ Level = DiagnosticIDs::Ignored;
+ }
unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
Level, (Description + " [" + CheckName + "]").str());
if (CheckNamesByDiagnosticID.count(ID) == 0)
Added: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nolint.cpp?rev=202452&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Thu Feb 27 18:27:50 2014
@@ -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]
More information about the cfe-commits
mailing list