Skip to content

Commit

Permalink
Bumping up to 0.26.0 (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
belav authored Nov 7, 2023
1 parent 9f2673f commit a8a6683
Show file tree
Hide file tree
Showing 29 changed files with 171 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.25.0",
"version": "0.26.0",
"commands": [
"dotnet-csharpier"
]
Expand Down
18 changes: 12 additions & 6 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_Std
var result = await new CsharpierProcess().ExecuteAsync();

result.ExitCode.Should().Be(1);
result.ErrorOutput
result
.ErrorOutput
.Should()
.Contain("directoryOrFile is required when not piping stdin to CSharpier");
}
Expand Down Expand Up @@ -170,7 +171,8 @@ public async Task Should_Print_NotFound()
var result = await new CsharpierProcess().WithArguments("/BasicFile.cs").ExecuteAsync();

result.Output.Should().BeEmpty();
result.ErrorOutput
result
.ErrorOutput
.Should()
.StartWith("There was no file or directory found at /BasicFile.cs");
result.ExitCode.Should().Be(1);
Expand Down Expand Up @@ -199,7 +201,8 @@ public async Task With_Check_Should_Write_Unformatted_File()
.WithArguments("CheckUnformatted.cs --check")
.ExecuteAsync();

result.ErrorOutput
result
.ErrorOutput
.Replace("\\", "/")
.Should()
.StartWith("Error ./CheckUnformatted.cs - Was not formatted.");
Expand Down Expand Up @@ -242,7 +245,8 @@ public async Task Should_Write_Error_With_Multiple_Piped_Files(string input, str
.WithPipedInput($"{input}{'\u0003'}{invalidFile}{'\u0003'}")
.ExecuteAsync();

result.ErrorOutput
result
.ErrorOutput
.Should()
.Be(
$"Error {output} - Failed to compile so was not formatted.{Environment.NewLine} (1,26): error CS1513: }} expected{Environment.NewLine}"
Expand Down Expand Up @@ -341,7 +345,8 @@ await this.WriteFileAsync(

var result = await new CsharpierProcess().WithArguments(".").ExecuteAsync();

result.ErrorOutput
result
.ErrorOutput
.Should()
.Contain("uses version 99 of CSharpier.MsBuild which is a mismatch with version");
result.ExitCode.Should().Be(1);
Expand Down Expand Up @@ -504,7 +509,8 @@ public CsharpierProcess()
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "dotnet-csharpier.dll");

this.command = CliWrap.Cli
this.command = CliWrap
.Cli
.Wrap("dotnet")
.WithArguments(path)
.WithWorkingDirectory(testFileDirectory)
Expand Down
13 changes: 7 additions & 6 deletions Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using CSharpier.Cli.Options;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Text;
using CSharpier.Cli.Options;
using CSharpier.Utilities;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -153,9 +153,9 @@ CancellationToken cancellationToken
cancellationToken
);

var originalDirectoryOrFile = commandLineOptions.OriginalDirectoryOrFilePaths[
x
].Replace("\\", "/");
var originalDirectoryOrFile = commandLineOptions
.OriginalDirectoryOrFilePaths[x]
.Replace("\\", "/");

var formattingCache = await FormattingCacheFactory.InitializeAsync(
commandLineOptions,
Expand Down Expand Up @@ -215,7 +215,8 @@ await FormatPhysicalFile(
return 1;
}

var tasks = fileSystem.Directory
var tasks = fileSystem
.Directory
.EnumerateFiles(directoryOrFilePath, "*.cs", SearchOption.AllDirectories)
.Select(o =>
{
Expand Down
6 changes: 3 additions & 3 deletions Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ IFileSystem fileSystem

while (directoryInfo is not null)
{
var file = fileSystem.FileInfo.FromFileName(
fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig")
);
var file = fileSystem
.FileInfo
.FromFileName(fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig"));
if (file.Exists)
{
editorConfigFiles.Add(file);
Expand Down
14 changes: 8 additions & 6 deletions Src/CSharpier.Cli/FormattingCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ 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(
Expand Down
9 changes: 6 additions & 3 deletions Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public static class HasMismatchedCliAndMsBuildVersions
{
public static bool Check(string directoryName, IFileSystem fileSystem, ILogger logger)
{
var csProjPaths = fileSystem.Directory
var csProjPaths = fileSystem
.Directory
.EnumerateFiles(directoryName, "*.csproj", SearchOption.AllDirectories)
.ToArray();

var versionOfDotnetTool = typeof(CommandLineFormatter).Assembly
var versionOfDotnetTool = typeof(CommandLineFormatter)
.Assembly
.GetName()
.Version!.ToString(3);
.Version!
.ToString(3);

string? GetPackagesVersion(string pathToCsProj)
{
Expand Down
7 changes: 3 additions & 4 deletions Src/CSharpier.Cli/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ var line in await fileSystem.File.ReadAllLinesAsync(ignoreFilePath, cancellation
var directoryInfo = fileSystem.DirectoryInfo.FromDirectoryName(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;
Expand Down
8 changes: 3 additions & 5 deletions Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ 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);
}
}
}
3 changes: 2 additions & 1 deletion Src/CSharpier.FakeGenerators/ValidNodeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public static class ValidNodeTypes
{
public static IList<Type> Get()
{
return typeof(CompilationUnitSyntax).Assembly
return typeof(CompilationUnitSyntax)
.Assembly
.GetTypes()
.Where(
o =>
Expand Down
4 changes: 3 additions & 1 deletion Src/CSharpier.Generators/NodePrinterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class NodePrinterGenerator : TemplatedGenerator

protected override object GetModel(GeneratorExecutionContext context)
{
var nodeTypes = context.Compilation.SyntaxTrees
var nodeTypes = context
.Compilation
.SyntaxTrees
.Where(o => o.FilePath.Contains("SyntaxNodePrinters"))
.Select(o => Path.GetFileNameWithoutExtension(o.FilePath))
.Select(
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.MsBuild.Test/CSharpier.MsBuild.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0">
<PackageReference Include="CSharpier.MsBuild" Version="0.26.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class FormattingTestsGenerator : TemplatedGenerator

protected override object GetModel(GeneratorExecutionContext context)
{
var tests = context.AdditionalFiles
var tests = context
.AdditionalFiles
.Where(
o =>
o.Path.EndsWith(".test")
Expand Down
38 changes: 25 additions & 13 deletions Src/CSharpier.Tests/CommandLineFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.IO.Abstractions.TestingHelpers;
using System.Text;
using CSharpier.Cli;
using FluentAssertions;
using NUnit.Framework;
using System.IO.Abstractions.TestingHelpers;

namespace CSharpier.Tests;

Expand All @@ -24,7 +24,8 @@ public void Format_Writes_Failed_To_Compile()

var result = this.Format(context);

result.OutputLines
result
.OutputLines
.First()
.Should()
.Be("Warning ./Invalid.cs - Failed to compile so was not formatted.");
Expand All @@ -38,7 +39,8 @@ public void Format_Writes_Failed_To_Compile_For_Subdirectory()

var result = this.Format(context, directoryOrFilePaths: "Subdirectory");

result.OutputLines
result
.OutputLines
.First()
.Should()
.Be("Warning ./Subdirectory/Invalid.cs - Failed to compile so was not formatted.");
Expand All @@ -55,7 +57,8 @@ public void Format_Writes_Failed_To_Compile_For_FullPath()
directoryOrFilePaths: Path.Combine(context.GetRootPath(), "Subdirectory")
);

result.OutputLines
result
.OutputLines
.First()
.Should()
.Be(
Expand All @@ -71,7 +74,8 @@ public void Format_Writes_Failed_To_Compile_With_Directory()

var result = this.Format(context);

result.OutputLines
result
.OutputLines
.First()
.Should()
.Be("Warning ./Directory/Invalid.cs - Failed to compile so was not formatted.");
Expand All @@ -85,7 +89,8 @@ public void Format_Writes_Unsupported()

var result = this.Format(context, directoryOrFilePaths: "Unsupported.js");

result.OutputLines
result
.OutputLines
.First()
.Should()
.Be(@"Warning ./Unsupported.js - Is an unsupported file type.");
Expand Down Expand Up @@ -133,7 +138,8 @@ public void Works_With_MSBuild_Version_Checking(string version, bool shouldPass)
else
{
result.ExitCode.Should().Be(1);
result.ErrorOutputLines
result
.ErrorOutputLines
.First()
.Should()
.EndWith(
Expand Down Expand Up @@ -161,7 +167,8 @@ public void Works_With_MSBuild_Version_Checking_When_No_Version_Specified()
var result = this.Format(context);

result.ExitCode.Should().Be(0);
result.OutputLines
result
.OutputLines
.First()
.Should()
.EndWith($"Test.csproj uses an unknown version of CSharpier.MsBuild");
Expand Down Expand Up @@ -210,7 +217,8 @@ bool shouldPass
else
{
result.ExitCode.Should().Be(1);
result.ErrorOutputLines
result
.ErrorOutputLines
.First()
.Should()
.EndWith(
Expand Down Expand Up @@ -275,7 +283,8 @@ public void Format_Checks_Unformatted_File()

result.ExitCode.Should().Be(1);
context.GetFileContent(unformattedFilePath).Should().Be(UnformattedClassContent);
result.ErrorOutputLines
result
.ErrorOutputLines
.First()
.Should()
.StartWith("Error ./Unformatted.cs - Was not formatted.");
Expand Down Expand Up @@ -440,7 +449,8 @@ public void Ignore_Reports_Errors()
var result = this.Format(context);

result.ExitCode.Should().Be(1);
result.ErrorOutputLines
result
.ErrorOutputLines
.First()
.Replace("\\", "/")
.Should()
Expand Down Expand Up @@ -500,7 +510,8 @@ public void File_With_Compilation_Error_Should_Not_Lose_Code()
var result = this.Format(context);

context.GetFileContent("Invalid.cs").Should().Be(contents);
result.OutputLines
result
.OutputLines
.First()
.Should()
.Be("Warning ./Invalid.cs - Failed to compile so was not formatted.");
Expand Down Expand Up @@ -557,7 +568,8 @@ public void Empty_Config_Files_Should_Log_Warning(string configFileName)

var result = this.Format(context);

result.OutputLines
result
.OutputLines
.First()
.Replace("\\", "/")
.Should()
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/DocPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@ private static string Print(
bool useTabs = false
)
{
return DocPrinter.DocPrinter
return DocPrinter
.DocPrinter
.Print(
doc,
new PrinterOptions
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/DocUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void RemoveInitialDoubleHardLine_Should_Remove_Single_HardLine()

DocUtilities.RemoveInitialDoubleHardLine(doc);

concat.Contents
concat
.Contents
.Should()
.BeEquivalentTo(new List<Doc> { Doc.HardLine, Doc.Null, Doc.HardLine });
}
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/FormattingTests/LineEndingEdgeCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void MethodName()
CancellationToken.None
);

result.Code
result
.Code
.Should()
.Be(unformattedCode.ReplaceLineEndings(endOfLine == EndOfLine.LF ? "\n" : "\r\n"));
}
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/MissingTypeChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void Ensure_There_Are_No_Missing_Types()
.Select(o => Path.GetFileNameWithoutExtension(o) + "Syntax")
.ToList();

var syntaxNodeTypes = typeof(CompilationUnitSyntax).Assembly
var syntaxNodeTypes = typeof(CompilationUnitSyntax)
.Assembly
.GetTypes()
.Where(o => !o.IsAbstract && typeof(CSharpSyntaxNode).IsAssignableFrom(o))
.ToList();
Expand Down
Loading

0 comments on commit a8a6683

Please sign in to comment.