Skip to content

Commit

Permalink
format with 0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Jan 21, 2024
1 parent cedd480 commit 56ff119
Show file tree
Hide file tree
Showing 36 changed files with 211 additions and 279 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.26.0",
"version": "0.27.0",
"commands": [
"dotnet-csharpier"
]
Expand Down
18 changes: 6 additions & 12 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: }}"
);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("\\", "/");
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 @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions Src/CSharpier.Cli/FormattingCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions Src/CSharpier.Cli/HasMismatchedCliAndMsBuildVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 4 additions & 3 deletions Src/CSharpier.Cli/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Src/CSharpier.Cli/Options/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}
11 changes: 5 additions & 6 deletions Src/CSharpier.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 5 additions & 7 deletions Src/CSharpier.FakeGenerators/ValidNodeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ public static class ValidNodeTypes
public static IList<Type> 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();
Expand Down
19 changes: 7 additions & 12 deletions Src/CSharpier.Generators/NodePrinterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
25 changes: 10 additions & 15 deletions Src/CSharpier.Tests.Generators/FormattingTestsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
36 changes: 12 additions & 24 deletions Src/CSharpier.Tests/CommandLineFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand All @@ -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.");
}
Expand All @@ -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."
Expand All @@ -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.");
}
Expand All @@ -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.");
}
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -501,8 +492,7 @@ public void Ignore_Reports_Errors()

result.ExitCode.Should().Be(1);
result
.ErrorOutputLines
.First()
.ErrorOutputLines.First()
.Replace("\\", "/")
.Should()
.Contain(
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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.");
Expand Down
Loading

0 comments on commit 56ff119

Please sign in to comment.