From 56ff119c4eede0434297bca81f403f9ad8f4fc0c Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Sun, 21 Jan 2024 14:36:33 -0600 Subject: [PATCH] format with 0.27.0 --- .config/dotnet-tools.json | 2 +- Src/CSharpier.Cli.Tests/CliTests.cs | 18 ++--- Src/CSharpier.Cli/CommandLineFormatter.cs | 7 +- .../EditorConfig/EditorConfigParser.cs | 6 +- Src/CSharpier.Cli/FormattingCache.cs | 14 ++-- .../HasMismatchedCliAndMsBuildVersions.cs | 9 +-- Src/CSharpier.Cli/IgnoreFile.cs | 7 +- Src/CSharpier.Cli/Options/OptionsProvider.cs | 8 +-- .../PhysicalFileInfoAndWriter.cs | 8 ++- Src/CSharpier.Cli/Program.cs | 11 ++- .../ValidNodeTypes.cs | 12 ++-- .../NodePrinterGenerator.cs | 19 ++--- .../FormattingTestsGenerator.cs | 25 +++---- .../CommandLineFormatterTests.cs | 36 ++++------ Src/CSharpier.Tests/DocPrinterTests.cs | 3 +- Src/CSharpier.Tests/DocUtilitiesTests.cs | 3 +- .../FormattingTests/LineEndingEdgeCase.cs | 3 +- Src/CSharpier.Tests/MissingTypeChecker.cs | 3 +- .../SyntaxNodeComparerTests.cs | 72 +++++++++---------- .../CSharpierOptionsPage.cs | 6 +- .../CSharpierProcessProvider.cs | 10 ++- .../FormattingService.cs | 3 +- .../InfoBarService.cs | 9 ++- .../Formatters/CSharp/PreprocessorSymbols.cs | 45 +++++------- Src/CSharpier/SyntaxNodeComparer.cs | 4 +- .../SyntaxPrinter/MembersWithForcedLines.cs | 12 ++-- .../SyntaxPrinter/NamespaceLikePrinter.cs | 8 +-- .../BaseMethodDeclaration.cs | 3 +- .../BasePropertyDeclaration.cs | 21 +++--- .../SyntaxNodePrinters/BaseTypeDeclaration.cs | 10 +-- .../InterpolatedStringExpression.cs | 8 +-- .../InvocationExpression.cs | 28 ++++---- .../SyntaxNodePrinters/RecursivePattern.cs | 7 +- Src/CSharpier/SyntaxPrinter/Token.cs | 44 +++++------- Src/SyntaxFinder/ObjectInitializerWalker.cs | 4 +- Src/SyntaxFinder/Program.cs | 2 +- 36 files changed, 211 insertions(+), 279 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 9db012c79..9050204d1 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.26.0", + "version": "0.27.0", "commands": [ "dotnet-csharpier" ] diff --git a/Src/CSharpier.Cli.Tests/CliTests.cs b/Src/CSharpier.Cli.Tests/CliTests.cs index 919f91f24..79073536e 100644 --- a/Src/CSharpier.Cli.Tests/CliTests.cs +++ b/Src/CSharpier.Cli.Tests/CliTests.cs @@ -126,8 +126,7 @@ public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_Std result.ExitCode.Should().Be(1); result - .ErrorOutput - .Should() + .ErrorOutput.Should() .Contain("directoryOrFile is required when not piping stdin to CSharpier"); } @@ -202,8 +201,7 @@ public async Task Should_Print_NotFound() result.Output.Should().BeEmpty(); result - .ErrorOutput - .Should() + .ErrorOutput.Should() .StartWith("There was no file or directory found at /BasicFile.cs"); result.ExitCode.Should().Be(1); } @@ -232,8 +230,7 @@ public async Task With_Check_Should_Write_Unformatted_File() .ExecuteAsync(); result - .ErrorOutput - .Replace("\\", "/") + .ErrorOutput.Replace("\\", "/") .Should() .StartWith("Error ./CheckUnformatted.cs - Was not formatted."); result.ExitCode.Should().Be(1); @@ -276,8 +273,7 @@ public async Task Should_Write_Error_With_Multiple_Piped_Files(string input, str .ExecuteAsync(); result - .ErrorOutput - .Should() + .ErrorOutput.Should() .StartWith( $"Error {output} - Failed to compile so was not formatted.{Environment.NewLine} (1,26): error CS1513: }}" ); @@ -376,8 +372,7 @@ await this.WriteFileAsync( var result = await new CsharpierProcess().WithArguments(".").ExecuteAsync(); result - .ErrorOutput - .Should() + .ErrorOutput.Should() .Contain("uses version 99 of CSharpier.MsBuild which is a mismatch with version"); result.ExitCode.Should().Be(1); } @@ -540,8 +535,7 @@ public CsharpierProcess() var path = Path.Combine(Directory.GetCurrentDirectory(), "dotnet-csharpier.dll"); this.command = CliWrap - .Cli - .Wrap("dotnet") + .Cli.Wrap("dotnet") .WithArguments(path) .WithWorkingDirectory(testFileDirectory) .WithValidation(CommandResultValidation.None) diff --git a/Src/CSharpier.Cli/CommandLineFormatter.cs b/Src/CSharpier.Cli/CommandLineFormatter.cs index fede11338..5549f2ba5 100644 --- a/Src/CSharpier.Cli/CommandLineFormatter.cs +++ b/Src/CSharpier.Cli/CommandLineFormatter.cs @@ -238,8 +238,11 @@ await FormatPhysicalFile( } var tasks = fileSystem - .Directory - .EnumerateFiles(directoryOrFilePath, "*.cs", SearchOption.AllDirectories) + .Directory.EnumerateFiles( + directoryOrFilePath, + "*.cs", + SearchOption.AllDirectories + ) .Select(o => { var normalizedPath = o.Replace("\\", "/"); diff --git a/Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs b/Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs index 52c0a2589..ce630131c 100644 --- a/Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs +++ b/Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs @@ -39,9 +39,9 @@ IgnoreFile ignoreFile while (directoryInfo is not null) { - var file = fileSystem - .FileInfo - .New(fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig")); + var file = fileSystem.FileInfo.New( + fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig") + ); if (file.Exists) { editorConfigFiles.Add(file); diff --git a/Src/CSharpier.Cli/FormattingCache.cs b/Src/CSharpier.Cli/FormattingCache.cs index 1f7f617db..ee86cd315 100644 --- a/Src/CSharpier.Cli/FormattingCache.cs +++ b/Src/CSharpier.Cli/FormattingCache.cs @@ -148,14 +148,12 @@ public async Task ResolveAsync(CancellationToken cancellationToken) async Task WriteFile() { - await using var fileStream = this.fileSystem - .File - .Open( - this.cacheFile, - FileMode.OpenOrCreate, - FileAccess.ReadWrite, - FileShare.None - ); + await using var fileStream = this.fileSystem.File.Open( + this.cacheFile, + FileMode.OpenOrCreate, + FileAccess.ReadWrite, + FileShare.None + ); await using var streamWriter = new StreamWriter(fileStream); await streamWriter.WriteAsync( JsonSerializer.Serialize( diff --git a/Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs b/Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs index 410883926..a656ab59f 100644 --- a/Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs +++ b/Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs @@ -10,15 +10,12 @@ public static class HasMismatchedCliAndMsBuildVersions public static bool Check(string directoryName, IFileSystem fileSystem, ILogger logger) { var csProjPaths = fileSystem - .Directory - .EnumerateFiles(directoryName, "*.csproj", SearchOption.AllDirectories) + .Directory.EnumerateFiles(directoryName, "*.csproj", SearchOption.AllDirectories) .ToArray(); var versionOfDotnetTool = typeof(CommandLineFormatter) - .Assembly - .GetName() - .Version! - .ToString(3); + .Assembly.GetName() + .Version!.ToString(3); string? GetPackagesVersion(string pathToCsProj) { diff --git a/Src/CSharpier.Cli/IgnoreFile.cs b/Src/CSharpier.Cli/IgnoreFile.cs index dc64df3d8..c354d2ccf 100644 --- a/Src/CSharpier.Cli/IgnoreFile.cs +++ b/Src/CSharpier.Cli/IgnoreFile.cs @@ -89,9 +89,10 @@ var line in await fileSystem.File.ReadAllLinesAsync(ignoreFilePath, cancellation var directoryInfo = fileSystem.DirectoryInfo.New(baseDirectoryPath); while (directoryInfo != null) { - var ignoreFilePath = fileSystem - .Path - .Combine(directoryInfo.FullName, ".csharpierignore"); + var ignoreFilePath = fileSystem.Path.Combine( + directoryInfo.FullName, + ".csharpierignore" + ); if (fileSystem.File.Exists(ignoreFilePath)) { return ignoreFilePath; diff --git a/Src/CSharpier.Cli/Options/OptionsProvider.cs b/Src/CSharpier.Cli/Options/OptionsProvider.cs index f767fffe2..20437448a 100644 --- a/Src/CSharpier.Cli/Options/OptionsProvider.cs +++ b/Src/CSharpier.Cli/Options/OptionsProvider.cs @@ -89,11 +89,11 @@ public PrinterOptions GetPrinterOptionsFor(string filePath) ArgumentNullException.ThrowIfNull(directoryName); - var resolvedEditorConfig = this.editorConfigs.FirstOrDefault( - o => directoryName.StartsWith(o.DirectoryName) + var resolvedEditorConfig = this.editorConfigs.FirstOrDefault(o => + directoryName.StartsWith(o.DirectoryName) ); - var resolvedCSharpierConfig = this.csharpierConfigs.FirstOrDefault( - o => directoryName.StartsWith(o.DirectoryName) + var resolvedCSharpierConfig = this.csharpierConfigs.FirstOrDefault(o => + directoryName.StartsWith(o.DirectoryName) ); if (resolvedEditorConfig is null && resolvedCSharpierConfig is null) diff --git a/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs b/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs index 1b4e240a7..751156fa3 100644 --- a/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs +++ b/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs @@ -15,9 +15,11 @@ public void WriteResult(CodeFormatterResult result, FileToFormatInfo fileToForma { if (result.Code != fileToFormatInfo.FileContents) { - this.FileSystem - .File - .WriteAllText(fileToFormatInfo.Path, result.Code, fileToFormatInfo.Encoding); + this.FileSystem.File.WriteAllText( + fileToFormatInfo.Path, + result.Code, + fileToFormatInfo.Encoding + ); } } } diff --git a/Src/CSharpier.Cli/Program.cs b/Src/CSharpier.Cli/Program.cs index 0d6375e46..9f2d17e05 100644 --- a/Src/CSharpier.Cli/Program.cs +++ b/Src/CSharpier.Cli/Program.cs @@ -84,12 +84,11 @@ CancellationToken cancellationToken else { directoryOrFile = directoryOrFile! - .Select( - o => - o == "." - // .csharpierignore gets confused by . so just don't include it - ? Directory.GetCurrentDirectory() - : Path.Combine(Directory.GetCurrentDirectory(), o) + .Select(o => + o == "." + // .csharpierignore gets confused by . so just don't include it + ? Directory.GetCurrentDirectory() + : Path.Combine(Directory.GetCurrentDirectory(), o) ) .ToArray(); } diff --git a/Src/CSharpier.FakeGenerators/ValidNodeTypes.cs b/Src/CSharpier.FakeGenerators/ValidNodeTypes.cs index bafc20789..ec194ceb7 100644 --- a/Src/CSharpier.FakeGenerators/ValidNodeTypes.cs +++ b/Src/CSharpier.FakeGenerators/ValidNodeTypes.cs @@ -8,13 +8,11 @@ public static class ValidNodeTypes public static IList Get() { return typeof(CompilationUnitSyntax) - .Assembly - .GetTypes() - .Where( - o => - !o.IsAbstract - && typeof(CSharpSyntaxNode).IsAssignableFrom(o) - && !Ignored.UnsupportedNodes.Contains(o.Name) + .Assembly.GetTypes() + .Where(o => + !o.IsAbstract + && typeof(CSharpSyntaxNode).IsAssignableFrom(o) + && !Ignored.UnsupportedNodes.Contains(o.Name) ) .OrderBy(o => o.Name) .ToList(); diff --git a/Src/CSharpier.Generators/NodePrinterGenerator.cs b/Src/CSharpier.Generators/NodePrinterGenerator.cs index 9d04bf2b2..1c12a959d 100644 --- a/Src/CSharpier.Generators/NodePrinterGenerator.cs +++ b/Src/CSharpier.Generators/NodePrinterGenerator.cs @@ -13,19 +13,14 @@ public class NodePrinterGenerator : TemplatedGenerator protected override object GetModel(GeneratorExecutionContext context) { var nodeTypes = context - .Compilation - .SyntaxTrees - .Where(o => o.FilePath.Contains("SyntaxNodePrinters")) + .Compilation.SyntaxTrees.Where(o => o.FilePath.Contains("SyntaxNodePrinters")) .Select(o => Path.GetFileNameWithoutExtension(o.FilePath)) - .Select( - fileName => - new - { - PrinterName = fileName, - SyntaxNodeName = fileName + "Syntax", - VariableName = char.ToLower(fileName[0]) + fileName[1..] - } - ) + .Select(fileName => new + { + PrinterName = fileName, + SyntaxNodeName = fileName + "Syntax", + VariableName = char.ToLower(fileName[0]) + fileName[1..] + }) .OrderBy(o => o.SyntaxNodeName) .ToArray(); diff --git a/Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs b/Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs index 8baff8f9f..5b78aa36c 100644 --- a/Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs +++ b/Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs @@ -11,22 +11,17 @@ public class FormattingTestsGenerator : TemplatedGenerator protected override object GetModel(GeneratorExecutionContext context) { var tests = context - .AdditionalFiles - .Where( - o => - o.Path.EndsWith(".test") - && !o.Path.EndsWith(".actual.test") - && !o.Path.EndsWith(".expected.test") + .AdditionalFiles.Where(o => + o.Path.EndsWith(".test") + && !o.Path.EndsWith(".actual.test") + && !o.Path.EndsWith(".expected.test") ) - .Select( - o => - new - { - Name = Path.GetFileNameWithoutExtension(o.Path), - FileExtension = new FileInfo(o.Path).Directory!.Name, - UseTabs = Path.GetFileNameWithoutExtension(o.Path).EndsWith("_Tabs") - } - ); + .Select(o => new + { + Name = Path.GetFileNameWithoutExtension(o.Path), + FileExtension = new FileInfo(o.Path).Directory!.Name, + UseTabs = Path.GetFileNameWithoutExtension(o.Path).EndsWith("_Tabs") + }); return new { Tests = tests }; } diff --git a/Src/CSharpier.Tests/CommandLineFormatterTests.cs b/Src/CSharpier.Tests/CommandLineFormatterTests.cs index 5e68e150d..f4cdcc2f5 100644 --- a/Src/CSharpier.Tests/CommandLineFormatterTests.cs +++ b/Src/CSharpier.Tests/CommandLineFormatterTests.cs @@ -25,8 +25,7 @@ public void Format_Writes_Failed_To_Compile() var result = this.Format(context); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be("Warning ./Invalid.cs - Failed to compile so was not formatted."); } @@ -40,8 +39,7 @@ public void Format_Writes_Failed_To_Compile_For_Subdirectory() var result = this.Format(context, directoryOrFilePaths: "Subdirectory"); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be("Warning ./Subdirectory/Invalid.cs - Failed to compile so was not formatted."); } @@ -58,8 +56,7 @@ public void Format_Writes_Failed_To_Compile_For_FullPath() ); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be( $"Warning {context.GetRootPath().Replace('\\', '/')}/Subdirectory/Invalid.cs - Failed to compile so was not formatted." @@ -75,8 +72,7 @@ public void Format_Writes_Failed_To_Compile_With_Directory() var result = this.Format(context); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be("Warning ./Directory/Invalid.cs - Failed to compile so was not formatted."); } @@ -90,8 +86,7 @@ public void Format_Writes_Unsupported() var result = this.Format(context, directoryOrFilePaths: "Unsupported.js"); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be(@"Warning ./Unsupported.js - Is an unsupported file type."); } @@ -139,8 +134,7 @@ public void Works_With_MSBuild_Version_Checking(string version, bool shouldPass) { result.ExitCode.Should().Be(1); result - .ErrorOutputLines - .First() + .ErrorOutputLines.First() .Should() .EndWith( $@"Test.csproj uses version {version} of CSharpier.MsBuild which is a mismatch with version {currentVersion}" @@ -168,8 +162,7 @@ public void Works_With_MSBuild_Version_Checking_When_No_Version_Specified() result.ExitCode.Should().Be(0); result - .OutputLines - .First() + .OutputLines.First() .Should() .EndWith($"Test.csproj uses an unknown version of CSharpier.MsBuild"); } @@ -218,8 +211,7 @@ bool shouldPass { result.ExitCode.Should().Be(1); result - .ErrorOutputLines - .First() + .ErrorOutputLines.First() .Should() .EndWith( $@"Test.csproj uses version {version} of CSharpier.MsBuild which is a mismatch with version {currentVersion}" @@ -284,8 +276,7 @@ public void Format_Checks_Unformatted_File() result.ExitCode.Should().Be(1); context.GetFileContent(unformattedFilePath).Should().Be(UnformattedClassContent); result - .ErrorOutputLines - .First() + .ErrorOutputLines.First() .Should() .StartWith("Error ./Unformatted.cs - Was not formatted."); } @@ -501,8 +492,7 @@ public void Ignore_Reports_Errors() result.ExitCode.Should().Be(1); result - .ErrorOutputLines - .First() + .ErrorOutputLines.First() .Replace("\\", "/") .Should() .Contain( @@ -562,8 +552,7 @@ public void File_With_Compilation_Error_Should_Not_Lose_Code() context.GetFileContent("Invalid.cs").Should().Be(contents); result - .OutputLines - .First() + .OutputLines.First() .Should() .Be("Warning ./Invalid.cs - Failed to compile so was not formatted."); } @@ -620,8 +609,7 @@ public void Empty_Config_Files_Should_Log_Warning(string configFileName) var result = this.Format(context); result - .OutputLines - .First() + .OutputLines.First() .Replace("\\", "/") .Should() .Be($"Warning The configuration file at {configPath} was empty."); diff --git a/Src/CSharpier.Tests/DocPrinterTests.cs b/Src/CSharpier.Tests/DocPrinterTests.cs index bf3b6b0d4..71468f889 100644 --- a/Src/CSharpier.Tests/DocPrinterTests.cs +++ b/Src/CSharpier.Tests/DocPrinterTests.cs @@ -757,8 +757,7 @@ private static string Print( ) { return DocPrinter - .DocPrinter - .Print( + .DocPrinter.Print( doc, new PrinterOptions { diff --git a/Src/CSharpier.Tests/DocUtilitiesTests.cs b/Src/CSharpier.Tests/DocUtilitiesTests.cs index 96b085f0e..58815b68f 100644 --- a/Src/CSharpier.Tests/DocUtilitiesTests.cs +++ b/Src/CSharpier.Tests/DocUtilitiesTests.cs @@ -93,8 +93,7 @@ public void RemoveInitialDoubleHardLine_Should_Remove_Single_HardLine() DocUtilities.RemoveInitialDoubleHardLine(doc); concat - .Contents - .Should() + .Contents.Should() .BeEquivalentTo(new List { Doc.HardLine, Doc.Null, Doc.HardLine }); } diff --git a/Src/CSharpier.Tests/FormattingTests/LineEndingEdgeCase.cs b/Src/CSharpier.Tests/FormattingTests/LineEndingEdgeCase.cs index 0f5257291..74596cb11 100644 --- a/Src/CSharpier.Tests/FormattingTests/LineEndingEdgeCase.cs +++ b/Src/CSharpier.Tests/FormattingTests/LineEndingEdgeCase.cs @@ -37,8 +37,7 @@ void MethodName() ); result - .Code - .Should() + .Code.Should() .Be(unformattedCode.ReplaceLineEndings(endOfLine == EndOfLine.LF ? "\n" : "\r\n")); } } diff --git a/Src/CSharpier.Tests/MissingTypeChecker.cs b/Src/CSharpier.Tests/MissingTypeChecker.cs index 397aee7ef..137a4c616 100644 --- a/Src/CSharpier.Tests/MissingTypeChecker.cs +++ b/Src/CSharpier.Tests/MissingTypeChecker.cs @@ -29,8 +29,7 @@ public void Ensure_There_Are_No_Missing_Types() .ToList(); var syntaxNodeTypes = typeof(CompilationUnitSyntax) - .Assembly - .GetTypes() + .Assembly.GetTypes() .Where(o => !o.IsAbstract && typeof(CSharpSyntaxNode).IsAssignableFrom(o)) .ToList(); diff --git a/Src/CSharpier.Tests/SyntaxNodeComparerTests.cs b/Src/CSharpier.Tests/SyntaxNodeComparerTests.cs index 1752b5bd8..47b9cda1b 100644 --- a/Src/CSharpier.Tests/SyntaxNodeComparerTests.cs +++ b/Src/CSharpier.Tests/SyntaxNodeComparerTests.cs @@ -537,21 +537,21 @@ public void MethodName() public void RawStringLiterals_Work_With_Moving_Indentation_2() { var left = """" - CallMethod(CallMethod( - """ - SomeString - """, someValue)); - """"; + CallMethod(CallMethod( + """ + SomeString + """, someValue)); + """"; var right = """" - CallMethod( - CallMethod( - """ - SomeString - """, - someValue - ) - ); - """"; + CallMethod( + CallMethod( + """ + SomeString + """, + someValue + ) + ); + """"; var result = CompareSource(left, right); @@ -562,21 +562,21 @@ public void RawStringLiterals_Work_With_Moving_Indentation_2() public void RawStringLiterals_Work_With_Moving_Indentation_3() { var left = """" - CallMethod(CallMethod( - $$""" - SomeString - """, someValue)); - """"; + CallMethod(CallMethod( + $$""" + SomeString + """, someValue)); + """"; var right = """" - CallMethod( - CallMethod( - $$""" - SomeString - """, - someValue - ) - ); - """"; + CallMethod( + CallMethod( + $$""" + SomeString + """, + someValue + ) + ); + """"; var result = CompareSource(left, right); @@ -587,15 +587,15 @@ public void RawStringLiterals_Work_With_Moving_Indentation_3() public void RawStringLiterals_Error_With_Adding_Indentation_When_There_Was_None() { var left = """" - var x = $$""" - - """; - """"; + var x = $$""" + + """; + """"; var right = """" - var x = $$""" - - """; - """"; + var x = $$""" + + """; + """"; var result = CompareSource(left, right); diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierOptionsPage.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierOptionsPage.cs index 2c1ef46f0..0c78157c8 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierOptionsPage.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierOptionsPage.cs @@ -8,9 +8,9 @@ public class CSharpierOptionsPage : DialogPage public CSharpierOptionsPage() { - this.model = ThreadHelper - .JoinableTaskFactory - .Run(CSharpierOptions.GetLiveInstanceAsync); + this.model = ThreadHelper.JoinableTaskFactory.Run( + CSharpierOptions.GetLiveInstanceAsync + ); } public override object AutomationObject => this.model; diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs index c7cd140b2..c33f12d5e 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs @@ -268,12 +268,10 @@ private void DisplayFailureMessage() } }; - InfoBarService - .Instance - .ShowInfoBar( - "CSharpier could not be set up properly so formatting is not currently supported.", - new[] { actionButton } - ); + InfoBarService.Instance.ShowInfoBar( + "CSharpier could not be set up properly so formatting is not currently supported.", + new[] { actionButton } + ); } public void KillRunningProcesses() diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/FormattingService.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/FormattingService.cs index f1483d013..9dc4f0f71 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/FormattingService.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/FormattingService.cs @@ -52,8 +52,7 @@ public void Format(Document document) this.logger.Info("Formatting started for " + document.FullName + "."); var stopwatch = Stopwatch.StartNew(); - var newText = this.cSharpierProcessProvider - .GetProcessFor(document.FullName) + var newText = this.cSharpierProcessProvider.GetProcessFor(document.FullName) .FormatFile(text, document.FullName); this.logger.Info("Formatted in " + stopwatch.ElapsedMilliseconds + "ms"); diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/InfoBarService.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/InfoBarService.cs index 37d2727e9..bb5190f44 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/InfoBarService.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/InfoBarService.cs @@ -74,11 +74,10 @@ public void ShowInfoBar(string message, IEnumerable? button } var actions = (buttons ?? Enumerable.Empty()) - .Select( - o => - o.IsHyperLink - ? new InfoBarHyperlink(o.Text, o.Context) as InfoBarActionItem - : new InfoBarButton(o.Text, o.Context) + .Select(o => + o.IsHyperLink + ? new InfoBarHyperlink(o.Text, o.Context) as InfoBarActionItem + : new InfoBarButton(o.Text, o.Context) ) .ToArray(); var infoBarModel = new InfoBarModel( diff --git a/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs b/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs index dfa7d3a56..da4634887 100644 --- a/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs +++ b/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs @@ -35,16 +35,13 @@ public override void VisitLeadingTrivia(SyntaxToken token) } foreach ( - var syntaxTrivia in token - .LeadingTrivia - .Where( - syntaxTrivia => - syntaxTrivia.RawSyntaxKind() - is SyntaxKind.IfDirectiveTrivia - or SyntaxKind.ElifDirectiveTrivia - or SyntaxKind.ElseDirectiveTrivia - or SyntaxKind.EndIfDirectiveTrivia - ) + var syntaxTrivia in token.LeadingTrivia.Where(syntaxTrivia => + syntaxTrivia.RawSyntaxKind() + is SyntaxKind.IfDirectiveTrivia + or SyntaxKind.ElifDirectiveTrivia + or SyntaxKind.ElseDirectiveTrivia + or SyntaxKind.EndIfDirectiveTrivia + ) ) { this.Visit((CSharpSyntaxNode)syntaxTrivia.GetStructure()!); @@ -67,16 +64,14 @@ public override void VisitElifDirectiveTrivia(ElifDirectiveTriviaSyntax node) public override void VisitElseDirectiveTrivia(ElseDirectiveTriviaSyntax node) { - var allParameters = this.CurrentContext - .booleanExpressions - .SelectMany(o => o.Parameters) + var allParameters = this.CurrentContext.booleanExpressions.SelectMany(o => o.Parameters) .Distinct() .ToList(); var combinations = GenerateCombinations(allParameters); var functions = this.CurrentContext.booleanExpressions.Select(o => o.Function).ToList(); - var combination = combinations.FirstOrDefault( - combination => functions.All(o => !o(combination)) + var combination = combinations.FirstOrDefault(combination => + functions.All(o => !o(combination)) ); if (combination == null) @@ -86,15 +81,13 @@ public override void VisitElseDirectiveTrivia(ElseDirectiveTriviaSyntax node) // TODO it would be more efficient to not add a new boolean expression, because we know which // symbols we need - this.CurrentContext - .booleanExpressions - .Add( - new BooleanExpression - { - Parameters = combination.Where(o => o.Value).Select(o => o.Key).ToList(), - Function = o => o.All(p => p.Value) - } - ); + this.CurrentContext.booleanExpressions.Add( + new BooleanExpression + { + Parameters = combination.Where(o => o.Value).Select(o => o.Key).ToList(), + Function = o => o.All(p => p.Value) + } + ); } public override void VisitEndIfDirectiveTrivia(EndIfDirectiveTriviaSyntax node) @@ -135,8 +128,8 @@ private string[] GetSymbols(BooleanExpression booleanExpression) // but the else works a bit different var combinations = GenerateCombinations(booleanExpression.Parameters); - var possibleParameters = combinations.FirstOrDefault( - possibleParameters => booleanExpression.Function(possibleParameters) + var possibleParameters = combinations.FirstOrDefault(possibleParameters => + booleanExpression.Function(possibleParameters) ); return possibleParameters == null diff --git a/Src/CSharpier/SyntaxNodeComparer.cs b/Src/CSharpier/SyntaxNodeComparer.cs index 5d0ae595f..af3eeaf29 100644 --- a/Src/CSharpier/SyntaxNodeComparer.cs +++ b/Src/CSharpier/SyntaxNodeComparer.cs @@ -236,8 +236,8 @@ originalToken.Parent is InterpolatedStringExpressionSyntax { // this detects if we added indentation when there was none, or removed all indentation when there was some if ( - originalToken.ValueText.TrimStart([ '\r', '\n' ])[0] - != formattedToken.ValueText.TrimStart([ '\r', '\n' ])[0] + originalToken.ValueText.TrimStart(['\r', '\n'])[0] + != formattedToken.ValueText.TrimStart(['\r', '\n'])[0] ) { return NotEqual(originalToken.Span, formattedNode!.Span); diff --git a/Src/CSharpier/SyntaxPrinter/MembersWithForcedLines.cs b/Src/CSharpier/SyntaxPrinter/MembersWithForcedLines.cs index d9ba967cc..de771f466 100644 --- a/Src/CSharpier/SyntaxPrinter/MembersWithForcedLines.cs +++ b/Src/CSharpier/SyntaxPrinter/MembersWithForcedLines.cs @@ -78,12 +78,12 @@ or StructDeclarationSyntax if ( member is MethodDeclarationSyntax methodDeclaration && node is ClassDeclarationSyntax classDeclaration - && classDeclaration - .Modifiers - .Any(o => o.RawSyntaxKind() is SyntaxKind.AbstractKeyword) - && methodDeclaration - .Modifiers - .Any(o => o.RawSyntaxKind() is SyntaxKind.AbstractKeyword) + && classDeclaration.Modifiers.Any(o => + o.RawSyntaxKind() is SyntaxKind.AbstractKeyword + ) + && methodDeclaration.Modifiers.Any(o => + o.RawSyntaxKind() is SyntaxKind.AbstractKeyword + ) ) { blankLineIsForced = false; diff --git a/Src/CSharpier/SyntaxPrinter/NamespaceLikePrinter.cs b/Src/CSharpier/SyntaxPrinter/NamespaceLikePrinter.cs index 8fe0e4b2f..dd34f36d9 100644 --- a/Src/CSharpier/SyntaxPrinter/NamespaceLikePrinter.cs +++ b/Src/CSharpier/SyntaxPrinter/NamespaceLikePrinter.cs @@ -87,12 +87,12 @@ node is CompilationUnitSyntax compilationUnitSyntax if ( ( node is not CompilationUnitSyntax { AttributeLists.Count: > 0 } - && directiveTrivia.All( - o => o.RawSyntaxKind() is SyntaxKind.EndIfDirectiveTrivia + && directiveTrivia.All(o => + o.RawSyntaxKind() is SyntaxKind.EndIfDirectiveTrivia ) ) - || !directiveTrivia.All( - o => o.RawSyntaxKind() is SyntaxKind.EndIfDirectiveTrivia + || !directiveTrivia.All(o => + o.RawSyntaxKind() is SyntaxKind.EndIfDirectiveTrivia ) ) { diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index 2697b2d29..982d85779 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -83,8 +83,7 @@ void PrintMethodUnformattedWithoutAttributes(SyntaxTriviaList syntaxTriviaList) .GetLeadingTrivia() .First() .GetLocation() - .SourceSpan - .Start; + .SourceSpan.Start; var methodWithoutAttributes = node.GetText() .Replace( diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BasePropertyDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BasePropertyDeclaration.cs index ea68280b4..99aa401d9 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BasePropertyDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BasePropertyDeclaration.cs @@ -72,15 +72,12 @@ FormattingContext context { Doc separator = " "; if ( - node.AccessorList - .Accessors - .Any( - o => - o.Body != null - || o.ExpressionBody != null - || o.Modifiers.Any() - || o.AttributeLists.Any() - ) + node.AccessorList.Accessors.Any(o => + o.Body != null + || o.ExpressionBody != null + || o.Modifiers.Any() + || o.AttributeLists.Any() + ) ) { separator = Doc.Line; @@ -91,9 +88,9 @@ FormattingContext context separator, Token.Print(node.AccessorList.OpenBraceToken, context), Doc.Indent( - node.AccessorList - .Accessors - .Select(o => PrintAccessorDeclarationSyntax(o, separator, context)) + node.AccessorList.Accessors.Select(o => + PrintAccessorDeclarationSyntax(o, separator, context) + ) .ToArray() ), separator, diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseTypeDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseTypeDeclaration.cs index 034b7fb80..7ef35ffe1 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseTypeDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseTypeDeclaration.cs @@ -143,13 +143,9 @@ public static Doc Print(BaseTypeDeclarationSyntax node, FormattingContext contex } else if (node.OpenBraceToken.RawSyntaxKind() != SyntaxKind.None) { - Doc separator = node.CloseBraceToken - .LeadingTrivia - .Any( - o => - o.RawSyntaxKind() - is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) - ) + Doc separator = node.CloseBraceToken.LeadingTrivia.Any(o => + o.RawSyntaxKind() is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) + ) ? Doc.Line : " "; diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs index ddb248afa..37bafffb6 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs @@ -65,10 +65,10 @@ private static Doc RawString(InterpolatedStringExpressionSyntax node, Formatting continue; } - var lines = textSyntax - .TextToken - .ValueText - .Split(lineSeparators, StringSplitOptions.None); + var lines = textSyntax.TextToken.ValueText.Split( + lineSeparators, + StringSplitOptions.None + ); for (var index = 0; index < lines.Length; index++) { var line = lines[index]; diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs index 781b45b7d..0cc74f751 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs @@ -37,16 +37,15 @@ public static Doc PrintMemberChain(ExpressionSyntax node, FormattingContext cont && ( groups .Skip(shouldMergeFirstTwoGroups ? 1 : 0) - .Any( - o => - o.Last().Node - is not ( - InvocationExpressionSyntax - or PostfixUnaryExpressionSyntax - { - Operand: InvocationExpressionSyntax - } - ) + .Any(o => + o.Last().Node + is not ( + InvocationExpressionSyntax + or PostfixUnaryExpressionSyntax + { + Operand: InvocationExpressionSyntax + } + ) ) // if the last group contains just a !, make sure it doesn't end up on a new line || ( @@ -70,11 +69,10 @@ or PostfixUnaryExpressionSyntax return oneLine.Skip(1).Any(DocUtilities.ContainsBreak) - || groups[0].Any( - o => - o.Node - is ArrayCreationExpressionSyntax - or ObjectCreationExpressionSyntax { Initializer: not null } + || groups[0].Any(o => + o.Node + is ArrayCreationExpressionSyntax + or ObjectCreationExpressionSyntax { Initializer: not null } ) ? expanded : Doc.ConditionalGroup(Doc.Concat(oneLine), expanded); diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/RecursivePattern.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/RecursivePattern.cs index 7ec708830..33a2e9a71 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/RecursivePattern.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/RecursivePattern.cs @@ -76,10 +76,9 @@ node.Parent is SwitchExpressionArmSyntax or CasePatternSwitchLabelSyntax Token.PrintLeadingTrivia(node.PropertyPatternClause.OpenBraceToken, context), Doc.Group( node.Type != null - && !node.PropertyPatternClause - .OpenBraceToken - .LeadingTrivia - .Any(o => o.IsDirective || o.IsComment()) + && !node.PropertyPatternClause.OpenBraceToken.LeadingTrivia.Any(o => + o.IsDirective || o.IsComment() + ) ? Doc.Line : Doc.Null, Token.PrintWithoutLeadingTrivia( diff --git a/Src/CSharpier/SyntaxPrinter/Token.cs b/Src/CSharpier/SyntaxPrinter/Token.cs index 012fb4f55..6999b82b9 100644 --- a/Src/CSharpier/SyntaxPrinter/Token.cs +++ b/Src/CSharpier/SyntaxPrinter/Token.cs @@ -71,9 +71,10 @@ is InterpolatedStringExpressionSyntax } else if (syntaxToken.RawSyntaxKind() is SyntaxKind.MultiLineRawStringLiteralToken) { - var linesIncludingQuotes = syntaxToken - .Text - .Split(lineSeparators, StringSplitOptions.None); + var linesIncludingQuotes = syntaxToken.Text.Split( + lineSeparators, + StringSplitOptions.None + ); var lastLineIsIndented = linesIncludingQuotes[^1][0] is '\t' or ' '; var contents = new List { @@ -383,40 +384,27 @@ private static Doc PrintTrailingTrivia(SyntaxTriviaList trailingTrivia) public static bool HasComments(SyntaxToken syntaxToken) { - return syntaxToken - .LeadingTrivia - .Any( - o => - o.RawSyntaxKind() - is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) - ) - || syntaxToken - .TrailingTrivia - .Any( - o => - o.RawSyntaxKind() - is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) - ); + return syntaxToken.LeadingTrivia.Any(o => + o.RawSyntaxKind() is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) + ) + || syntaxToken.TrailingTrivia.Any(o => + o.RawSyntaxKind() is not (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia) + ); } public static bool HasLeadingCommentMatching(SyntaxNode node, Regex regex) { return node.GetLeadingTrivia() - .Any( - o => - o.RawSyntaxKind() is SyntaxKind.SingleLineCommentTrivia - && regex.IsMatch(o.ToString()) + .Any(o => + o.RawSyntaxKind() is SyntaxKind.SingleLineCommentTrivia + && regex.IsMatch(o.ToString()) ); } public static bool HasLeadingCommentMatching(SyntaxToken token, Regex regex) { - return token - .LeadingTrivia - .Any( - o => - o.RawSyntaxKind() is SyntaxKind.SingleLineCommentTrivia - && regex.IsMatch(o.ToString()) - ); + return token.LeadingTrivia.Any(o => + o.RawSyntaxKind() is SyntaxKind.SingleLineCommentTrivia && regex.IsMatch(o.ToString()) + ); } } diff --git a/Src/SyntaxFinder/ObjectInitializerWalker.cs b/Src/SyntaxFinder/ObjectInitializerWalker.cs index 6498eed84..e48216ffe 100644 --- a/Src/SyntaxFinder/ObjectInitializerWalker.cs +++ b/Src/SyntaxFinder/ObjectInitializerWalker.cs @@ -33,8 +33,8 @@ private void VisitNode(InitializerExpressionSyntax node) totalExpressions += node.Expressions.Count; if ( - node.Expressions.Any( - o => o.GetLeadingTrivia().Any(o => o.Kind() is SyntaxKind.EndOfLineTrivia) + node.Expressions.Any(o => + o.GetLeadingTrivia().Any(o => o.Kind() is SyntaxKind.EndOfLineTrivia) ) ) { diff --git a/Src/SyntaxFinder/Program.cs b/Src/SyntaxFinder/Program.cs index a561014ed..46ef30346 100644 --- a/Src/SyntaxFinder/Program.cs +++ b/Src/SyntaxFinder/Program.cs @@ -42,7 +42,7 @@ var contents = File.ReadAllText(file); var tree = CSharpSyntaxTree.ParseText(contents); - var syntaxWalker = constructor.Invoke([ file ]) as CSharpSyntaxWalker; + var syntaxWalker = constructor.Invoke([file]) as CSharpSyntaxWalker; syntaxWalker!.Visit(tree.GetRoot()); } );