@@ -297,10 +297,12 @@ std::string ClangTidyContext::getCheckName(unsigned DiagnosticID) const {
297297
298298ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer (
299299 ClangTidyContext &Ctx, DiagnosticsEngine *ExternalDiagEngine,
300- bool RemoveIncompatibleErrors, bool GetFixesFromNotes)
300+ bool RemoveIncompatibleErrors, bool GetFixesFromNotes,
301+ bool EnableNolintBlocks)
301302 : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine),
302303 RemoveIncompatibleErrors(RemoveIncompatibleErrors),
303- GetFixesFromNotes(GetFixesFromNotes), LastErrorRelatesToUserCode(false ),
304+ GetFixesFromNotes(GetFixesFromNotes),
305+ EnableNolintBlocks(EnableNolintBlocks), LastErrorRelatesToUserCode(false ),
304306 LastErrorPassesLineFilter(false ), LastErrorWasIgnored(false ) {}
305307
306308void ClangTidyDiagnosticConsumer::finalizeLastError () {
@@ -469,7 +471,8 @@ static bool
469471lineIsMarkedWithNOLINT (const ClangTidyContext &Context,
470472 SmallVectorImpl<ClangTidyError> &SuppressionErrors,
471473 bool AllowIO, const SourceManager &SM,
472- SourceLocation Loc, StringRef CheckName) {
474+ SourceLocation Loc, StringRef CheckName,
475+ bool EnableNolintBlocks) {
473476 // Get source code for this location.
474477 FileID File;
475478 unsigned Offset;
@@ -499,19 +502,21 @@ lineIsMarkedWithNOLINT(const ClangTidyContext &Context,
499502 return true ;
500503
501504 // Check if this line is within a NOLINT(BEGIN...END) block.
502- return lineIsWithinNolintBegin (Context, SuppressionErrors, SM, Loc, CheckName,
505+ return EnableNolintBlocks &&
506+ lineIsWithinNolintBegin (Context, SuppressionErrors, SM, Loc, CheckName,
503507 TextBeforeDiag, TextAfterDiag);
504508}
505509
506510static bool lineIsMarkedWithNOLINTinMacro (
507511 const Diagnostic &Info, const ClangTidyContext &Context,
508- SmallVectorImpl<ClangTidyError> &SuppressionErrors, bool AllowIO) {
512+ SmallVectorImpl<ClangTidyError> &SuppressionErrors, bool AllowIO,
513+ bool EnableNolintBlocks) {
509514 const SourceManager &SM = Info.getSourceManager ();
510515 SourceLocation Loc = Info.getLocation ();
511516 std::string CheckName = Context.getCheckName (Info.getID ());
512517 while (true ) {
513518 if (lineIsMarkedWithNOLINT (Context, SuppressionErrors, AllowIO, SM, Loc,
514- CheckName))
519+ CheckName, EnableNolintBlocks ))
515520 return true ;
516521 if (!Loc.isMacroID ())
517522 return false ;
@@ -526,12 +531,13 @@ namespace tidy {
526531bool shouldSuppressDiagnostic (
527532 DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
528533 ClangTidyContext &Context,
529- SmallVectorImpl<ClangTidyError> &SuppressionErrors, bool AllowIO) {
534+ SmallVectorImpl<ClangTidyError> &SuppressionErrors, bool AllowIO,
535+ bool EnableNolintBlocks) {
530536 return Info.getLocation ().isValid () &&
531537 DiagLevel != DiagnosticsEngine::Error &&
532538 DiagLevel != DiagnosticsEngine::Fatal &&
533539 lineIsMarkedWithNOLINTinMacro (Info, Context, SuppressionErrors,
534- AllowIO);
540+ AllowIO, EnableNolintBlocks );
535541}
536542
537543const llvm::StringMap<tooling::Replacements> *
@@ -561,7 +567,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
561567 return ;
562568
563569 SmallVector<ClangTidyError, 1 > SuppressionErrors;
564- if (shouldSuppressDiagnostic (DiagLevel, Info, Context, SuppressionErrors)) {
570+ if (shouldSuppressDiagnostic (DiagLevel, Info, Context, SuppressionErrors,
571+ EnableNolintBlocks)) {
565572 ++Context.Stats .ErrorsIgnoredNOLINT ;
566573 // Ignored a warning, should ignore related notes as well
567574 LastErrorWasIgnored = true ;
0 commit comments