@@ -351,9 +351,6 @@ static void outputReplacementsXML(const Replacements &Replaces) {
351
351
static bool
352
352
emitReplacementWarnings (const Replacements &Replaces, StringRef AssumedFileName,
353
353
const std::unique_ptr<llvm::MemoryBuffer> &Code) {
354
- if (Replaces.empty ())
355
- return false ;
356
-
357
354
unsigned Errors = 0 ;
358
355
if (WarnFormat && !NoWarnFormat) {
359
356
SourceMgr Mgr;
@@ -490,9 +487,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
490
487
Replacements Replaces = sortIncludes (*FormatStyle, Code->getBuffer (), Ranges,
491
488
AssumedFileName, &CursorPosition);
492
489
490
+ const bool IsJson = FormatStyle->isJson ();
491
+
493
492
// To format JSON insert a variable to trick the code into thinking its
494
493
// JavaScript.
495
- if (FormatStyle-> isJson () && !FormatStyle->DisableFormat ) {
494
+ if (IsJson && !FormatStyle->DisableFormat ) {
496
495
auto Err = Replaces.add (tooling::Replacement (
497
496
tooling::Replacement (AssumedFileName, 0 , 0 , " x = " )));
498
497
if (Err)
@@ -510,9 +509,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
510
509
Replacements FormatChanges =
511
510
reformat (*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status);
512
511
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) {
516
517
outputXML (Replaces, FormatChanges, Status, Cursor, CursorPosition);
517
518
} else {
518
519
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem (
0 commit comments