@@ -379,18 +379,13 @@ CancellationToken cancellationToken
379379
380380 cancellationToken . ThrowIfCancellationRequested ( ) ;
381381
382- CodeFormatterResult codeFormattingResult ;
383-
384- var sourceCodeKind = Path . GetExtension ( fileToFormatInfo . Path ) . EqualsIgnoreCase ( ".csx" )
385- ? SourceCodeKind . Script
386- : SourceCodeKind . Regular ;
382+ CodeFormatterResult ? codeFormattingResult ;
387383
388384 try
389385 {
390- codeFormattingResult = await CSharpFormatter . FormatAsync (
386+ codeFormattingResult = await CodeFormatter . FormatAsync (
391387 fileToFormatInfo . FileContents ,
392388 printerOptions ,
393- sourceCodeKind ,
394389 cancellationToken
395390 ) ;
396391 }
@@ -427,6 +422,12 @@ CancellationToken cancellationToken
427422 return ;
428423 }
429424
425+ if ( ! codeFormattingResult . WarningMessage . IsBlank ( ) )
426+ {
427+ fileIssueLogger . WriteWarning ( codeFormattingResult . WarningMessage ) ;
428+ return ;
429+ }
430+
430431 if ( ! codeFormattingResult . FailureMessage . IsBlank ( ) )
431432 {
432433 fileIssueLogger . WriteError ( codeFormattingResult . FailureMessage ) ;
@@ -435,35 +436,45 @@ CancellationToken cancellationToken
435436
436437 if ( ! commandLineOptions . Fast )
437438 {
438- var syntaxNodeComparer = new SyntaxNodeComparer (
439- fileToFormatInfo . FileContents ,
440- codeFormattingResult . Code ,
441- codeFormattingResult . ReorderedModifiers ,
442- codeFormattingResult . ReorderedUsingsWithDisabledText ,
443- codeFormattingResult . MovedTrailingTrivia ,
444- sourceCodeKind ,
445- cancellationToken
446- ) ;
447-
448- try
439+ if ( printerOptions . Formatter is Formatter . CSharp or Formatter . CSharpScript )
449440 {
450- var failure = await syntaxNodeComparer . CompareSourceAsync ( cancellationToken ) ;
451- if ( ! string . IsNullOrEmpty ( failure ) )
441+ var sourceCodeKind =
442+ printerOptions . Formatter is Formatter . CSharpScript
443+ ? SourceCodeKind . Script
444+ : SourceCodeKind . Regular ;
445+
446+ var syntaxNodeComparer = new SyntaxNodeComparer (
447+ fileToFormatInfo . FileContents ,
448+ codeFormattingResult . Code ,
449+ codeFormattingResult . ReorderedModifiers ,
450+ codeFormattingResult . ReorderedUsingsWithDisabledText ,
451+ codeFormattingResult . MovedTrailingTrivia ,
452+ sourceCodeKind ,
453+ cancellationToken
454+ ) ;
455+
456+ try
457+ {
458+ var failure = await syntaxNodeComparer . CompareSourceAsync ( cancellationToken ) ;
459+ if ( ! string . IsNullOrEmpty ( failure ) )
460+ {
461+ Interlocked . Increment (
462+ ref commandLineFormatterResult . FailedSyntaxTreeValidation
463+ ) ;
464+ fileIssueLogger . WriteError ( $ "Failed syntax tree validation.\n { failure } ") ;
465+ }
466+ }
467+ catch ( Exception ex )
452468 {
453469 Interlocked . Increment (
454- ref commandLineFormatterResult . FailedSyntaxTreeValidation
470+ ref commandLineFormatterResult . ExceptionsValidatingSource
455471 ) ;
456- fileIssueLogger . WriteError ( $ "Failed syntax tree validation.\n { failure } ") ;
457- }
458- }
459- catch ( Exception ex )
460- {
461- Interlocked . Increment ( ref commandLineFormatterResult . ExceptionsValidatingSource ) ;
462472
463- fileIssueLogger . WriteError (
464- "Failed with exception during syntax tree validation." ,
465- ex
466- ) ;
473+ fileIssueLogger . WriteError (
474+ "Failed with exception during syntax tree validation." ,
475+ ex
476+ ) ;
477+ }
467478 }
468479 }
469480
0 commit comments