@@ -425,20 +425,29 @@ clangTidyNoLintFixes(const clang::tidy::ClangTidyContext &CTContext,
425425
426426 auto StartCurLine = CodeTilDiag.find_last_of (' \n ' ) + 1 ;
427427 auto CurLine = CodeTilDiag.substr (StartCurLine);
428- elog (" CurLine: '{0}'" , CurLine);
429428 auto Indent = CurLine.take_while ([](char C) { return std::isspace (C); });
430429
430+ auto ExistingNoLintNextLineInsertPos = std::optional<int >();
431431 if (StartCurLine > 0 ) {
432432 auto StartPrevLine = CodeTilDiag.find_last_of (' \n ' , StartCurLine - 1 ) + 1 ;
433433 auto PrevLine =
434434 CodeTilDiag.substr (StartPrevLine, StartCurLine - StartPrevLine - 1 );
435- elog (" PrevLine: '{0}'" , PrevLine);
435+ auto NLPos = PrevLine.find (" NOLINTNEXTLINE(" );
436+ if (NLPos != StringRef::npos) {
437+ ExistingNoLintNextLineInsertPos =
438+ std::make_optional (PrevLine.find (" )" , NLPos));
439+ }
436440 }
437441
438- E.newText = llvm::formatv (" {0}// NOLINTNEXTLINE({1})\n " , Indent, RuleName);
439-
440442 auto InsertPos = sourceLocToPosition (SrcMgr, DiagLoc);
441- InsertPos.character = 0 ;
443+ if (ExistingNoLintNextLineInsertPos) {
444+ E.newText = llvm::formatv (" , {0}" , RuleName);
445+ InsertPos.line -= 1 ;
446+ InsertPos.character = *ExistingNoLintNextLineInsertPos;
447+ } else {
448+ E.newText = llvm::formatv (" {0}// NOLINTNEXTLINE({1})\n " , Indent, RuleName);
449+ InsertPos.character = 0 ;
450+ }
442451 E.range = {InsertPos, InsertPos};
443452
444453 return {F};
0 commit comments