@@ -351,9 +351,6 @@ static void outputReplacementsXML(const Replacements &Replaces) {
351351static bool
352352emitReplacementWarnings (const Replacements &Replaces, StringRef AssumedFileName,
353353 const std::unique_ptr<llvm::MemoryBuffer> &Code) {
354- if (Replaces.empty ())
355- return false ;
356-
357354 unsigned Errors = 0 ;
358355 if (WarnFormat && !NoWarnFormat) {
359356 SourceMgr Mgr;
@@ -490,9 +487,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
490487 Replacements Replaces = sortIncludes (*FormatStyle, Code->getBuffer (), Ranges,
491488 AssumedFileName, &CursorPosition);
492489
490+ const bool IsJson = FormatStyle->isJson ();
491+
493492 // To format JSON insert a variable to trick the code into thinking its
494493 // JavaScript.
495- if (FormatStyle-> isJson () && !FormatStyle->DisableFormat ) {
494+ if (IsJson && !FormatStyle->DisableFormat ) {
496495 auto Err = Replaces.add (tooling::Replacement (
497496 tooling::Replacement (AssumedFileName, 0 , 0 , " x = " )));
498497 if (Err)
@@ -510,9 +509,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
510509 Replacements FormatChanges =
511510 reformat (*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status);
512511 Replaces = Replaces.merge (FormatChanges);
513- if (OutputXML || DryRun) {
514- if (DryRun)
515- return emitReplacementWarnings (Replaces, AssumedFileName, Code);
512+ if (DryRun) {
513+ return Replaces.size () > (IsJson ? 1 : 0 ) &&
514+ emitReplacementWarnings (Replaces, AssumedFileName, Code);
515+ }
516+ if (OutputXML) {
516517 outputXML (Replaces, FormatChanges, Status, Cursor, CursorPosition);
517518 } else {
518519 IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem (
0 commit comments