aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/ClangTidyDiagnosticConsumer.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2016-05-04 21:18:31 +0000
committerAlexander Kornienko <alexfh@google.com>2016-05-04 21:18:31 +0000
commita8138626ba05dae23a7c7928e9d1c3d169b73dce (patch)
treea6be201818660b1b3dbb04464d6ff77c14ad0179 /clang-tidy/ClangTidyDiagnosticConsumer.cpp
parentefb05a5efa8393a491de819e8df79d92d84e43c5 (diff)
[clang-tidy] Apply NOLINT filtering to Clang warnings.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@268555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/ClangTidyDiagnosticConsumer.cpp')
-rw-r--r--clang-tidy/ClangTidyDiagnosticConsumer.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 48ae9224..e9a448ea 100644
--- a/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -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);