This revision was automatically updated to reflect the committed changes. Closed by commit rL295049: [clang-tidy] Add support for NOLINTNEXTLINE. (authored by d0k).
Changed prior to commit: https://reviews.llvm.org/D29899?vs=88352&id=88353#toc Repository: rL LLVM https://reviews.llvm.org/D29899 Files: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -272,13 +272,42 @@ 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; StringRef RestOfLine(CharacterData, P - CharacterData + 1); // 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; } Index: clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp +++ clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp @@ -0,0 +1,33 @@ +class A { A(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +// NOLINTNEXTLINE +class B { B(int i); }; + +// NOLINTNEXTLINE(we-dont-care-about-categories-yet) +class C { C(int i); }; + + +// NOLINTNEXTLINE + +class D { D(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +// NOLINTNEXTLINE +// +class E { E(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +#define MACRO(X) class X { X(int i); }; +MACRO(F) +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit +// NOLINTNEXTLINE +MACRO(G) + +#define MACRO_NOARG class H { H(int i); }; +// NOLINTNEXTLINE +MACRO_NOARG + +// CHECK-MESSAGES: Suppressed 4 warnings (4 NOLINT) + +// RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -272,13 +272,42 @@ 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; StringRef RestOfLine(CharacterData, P - CharacterData + 1); // 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; } Index: clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp +++ clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp @@ -0,0 +1,33 @@ +class A { A(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +// NOLINTNEXTLINE +class B { B(int i); }; + +// NOLINTNEXTLINE(we-dont-care-about-categories-yet) +class C { C(int i); }; + + +// NOLINTNEXTLINE + +class D { D(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +// NOLINTNEXTLINE +// +class E { E(int i); }; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit + +#define MACRO(X) class X { X(int i); }; +MACRO(F) +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit +// NOLINTNEXTLINE +MACRO(G) + +#define MACRO_NOARG class H { H(int i); }; +// NOLINTNEXTLINE +MACRO_NOARG + +// CHECK-MESSAGES: Suppressed 4 warnings (4 NOLINT) + +// RUN: %check_clang_tidy %s google-explicit-constructor %t --
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits