Example #1
0
 private void PerformCheck(string filePath, CSharpierResult result, string fileContents)
 {
     if (
         this.CommandLineOptions.Check &&
         !this.CommandLineOptions.ShouldWriteStandardOut &&
         result.Code != fileContents
         )
     {
         WriteLine(GetPath(filePath) + " - was not formatted");
         StringDiffer.PrintFirstDifference(result.Code, fileContents, this.Console);
         Interlocked.Increment(ref this.Result.UnformattedFiles);
     }
 }
Example #2
0
        private async Task PerformSyntaxTreeValidation(
            string file,
            string fileContents,
            CSharpierResult result,
            CancellationToken cancellationToken
            )
        {
            if (!this.CommandLineOptions.Fast)
            {
                var syntaxNodeComparer = new SyntaxNodeComparer(
                    fileContents,
                    result.Code,
                    cancellationToken
                    );

                try
                {
                    var failure = await syntaxNodeComparer.CompareSourceAsync(cancellationToken);

                    if (!string.IsNullOrEmpty(failure))
                    {
                        Interlocked.Increment(ref this.Result.FailedSyntaxTreeValidation);
                        WriteLine(GetPath(file) + " - failed syntax tree validation");
                        WriteLine(failure);
                    }
                }
                catch (Exception ex)
                {
                    Interlocked.Increment(ref this.Result.ExceptionsValidatingSource);
                    WriteLine(
                        GetPath(file)
                        + " - failed with exception during syntax tree validation"
                        + Environment.NewLine
                        + ex.Message
                        + ex.StackTrace
                        );
                }
            }
        }
Example #3
0
 private void WriteResult(
     string filePath,
     CSharpierResult result,
     string?fileContents,
     Encoding?encoding
     )
 {
     if (this.CommandLineOptions.ShouldWriteStandardOut)
     {
         this.Console.Write(result.Code);
     }
     else
     {
         if (
             !this.CommandLineOptions.Check &&
             !this.CommandLineOptions.SkipWrite &&
             result.Code != fileContents
             )
         {
             // purposely avoid async here, that way the file completely writes if the process gets cancelled while running.
             this.FileSystem.File.WriteAllText(filePath, result.Code, encoding);
         }
     }
 }