[clang-tidy] Apply NOLINT filtering to Clang warnings.

llvm-svn: 268555
This commit is contained in:
Alexander Kornienko 2016-05-04 21:18:31 +00:00
parent 946ca27b61
commit dbefbdb6d1
2 changed files with 32 additions and 16 deletions

View File

@ -174,20 +174,6 @@ DiagnosticBuilder ClangTidyContext::diag(
StringRef CheckName, SourceLocation Loc, StringRef Description,
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;
++Stats.ErrorsIgnoredNOLINT;
}
}
unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
Level, (Description + " [" + CheckName + "]").str());
if (CheckNamesByDiagnosticID.count(ID) == 0)
@ -290,8 +276,31 @@ void ClangTidyDiagnosticConsumer::finalizeLastError() {
LastErrorPassesLineFilter = false;
}
static bool LineIsMarkedWithNOLINT(SourceManager& SM, SourceLocation Loc) {
bool Invalid;
const char *CharacterData = SM.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) {
return true;
}
}
return false;
}
void ClangTidyDiagnosticConsumer::HandleDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
if (Info.getLocation().isValid() &&
DiagLevel != DiagnosticsEngine::Error &&
DiagLevel != DiagnosticsEngine::Fatal &&
LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) {
++Context.Stats.ErrorsIgnoredNOLINT;
return;
}
// Count warnings/errors.
DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s google-explicit-constructor %t
// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable %t -- -extra-arg=-Wunused-variable --
class A { A(int i); };
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
@ -6,4 +6,11 @@ class A { A(int i); };
class B { B(int i); }; // NOLINT
class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet)
// CHECK-MESSAGES: Suppressed 2 warnings (2 NOLINT)
void f() {
int i;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'i' [clang-diagnostic-unused-variable]
int j; // NOLINT
}
// CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT)