diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2017-02-14 12:47:56 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2017-02-14 12:47:56 +0000 |
| commit | d1013b44e305e8da235583b763b2308dafdb813f (patch) | |
| tree | 2b96956691e5c8bb1b1ffe0cb8c62eebd12aba5c /clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp | |
| parent | be2588fa7fb5a1677cc42e5a6236355c9cef0a56 (diff) | |
| download | bcm5719-llvm-d1013b44e305e8da235583b763b2308dafdb813f.tar.gz bcm5719-llvm-d1013b44e305e8da235583b763b2308dafdb813f.zip | |
[clang-tidy] Add support for NOLINTNEXTLINE.
Reviewers: alexfh
Subscribers: JDevlieghere, cfe-commits
Differential Revision: https://reviews.llvm.org/D29899
llvm-svn: 295049
Diffstat (limited to 'clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp index 2e8ca7d19d0..a68562c9cc3 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -272,6 +272,7 @@ static bool LineIsMarkedWithNOLINT(SourceManager &SM, SourceLocation Loc) { if (Invalid) return false; + // Check if there's a NOLINT on this line. const char *P = CharacterData; while (*P != '\0' && *P != '\r' && *P != '\n') ++P; @@ -279,6 +280,34 @@ static bool LineIsMarkedWithNOLINT(SourceManager &SM, SourceLocation Loc) { // FIXME: Handle /\bNOLINT\b(\([^)]*\))?/ as cpplint.py does. if (RestOfLine.find("NOLINT") != StringRef::npos) return true; + + // Check if there's a NOLINTNEXTLINE on the previous line. + const char *BufBegin = + SM.getCharacterData(SM.getLocForStartOfFile(SM.getFileID(Loc)), &Invalid); + if (Invalid || P == BufBegin) + return false; + + // Scan backwards over the current line. + P = CharacterData; + while (P != BufBegin && *P != '\n') + --P; + + // If we reached the begin of the file there is no line before it. + if (P == BufBegin) + return false; + + // Skip over the newline. + --P; + const char *LineEnd = P; + + // Now we're on the previous line. Skip to the beginning of it. + while (P != BufBegin && *P != '\n') + --P; + + RestOfLine = StringRef(P, LineEnd - P + 1); + if (RestOfLine.find("NOLINTNEXTLINE") != StringRef::npos) + return true; + return false; } |

