diff --git a/Src/CSharpier.Cli.Tests/CliTests.cs b/Src/CSharpier.Cli.Tests/CliTests.cs index 009a9751a..f71659151 100644 --- a/Src/CSharpier.Cli.Tests/CliTests.cs +++ b/Src/CSharpier.Cli.Tests/CliTests.cs @@ -152,6 +152,42 @@ public async Task Should_Format_Piped_File(string lineEnding) result.ExitCode.Should().Be(0); } + [Test] + public async Task Should_Format_Piped_File_With_Config() + { + await this.WriteFileAsync(".csharpierrc", "printWidth: 10"); + + var formattedContent1 = "var x =\n _________________longName;\n"; + var unformattedContent1 = "var x = _________________longName;\n"; + + var result = await new CsharpierProcess() + .WithPipedInput(unformattedContent1) + .ExecuteAsync(); + + result.Output.Should().Be(formattedContent1); + result.ExitCode.Should().Be(0); + } + + [Test] + public async Task Should_Format_Piped_File_With_EditorConfig() + { + await this.WriteFileAsync( + ".editorconfig", + @"[*] +max_line_length = 10" + ); + + var formattedContent1 = "var x =\n _________________longName;\n"; + var unformattedContent1 = "var x = _________________longName;\n"; + + var result = await new CsharpierProcess() + .WithPipedInput(unformattedContent1) + .ExecuteAsync(); + + result.Output.Should().Be(formattedContent1); + result.ExitCode.Should().Be(0); + } + [Test] public async Task Should_Format_Unicode() { diff --git a/Src/CSharpier.Cli/CommandLineFormatter.cs b/Src/CSharpier.Cli/CommandLineFormatter.cs index c45a179aa..cd74f9e1d 100644 --- a/Src/CSharpier.Cli/CommandLineFormatter.cs +++ b/Src/CSharpier.Cli/CommandLineFormatter.cs @@ -24,7 +24,15 @@ CancellationToken cancellationToken if (commandLineOptions.StandardInFileContents != null) { - var filePath = commandLineOptions.DirectoryOrFilePaths[0]; + var directoryOrFilePath = commandLineOptions.DirectoryOrFilePaths[0]; + var directoryPath = fileSystem.Directory.Exists(directoryOrFilePath) + ? directoryOrFilePath + : fileSystem.Path.GetDirectoryName(directoryOrFilePath); + var filePath = + directoryOrFilePath != directoryPath + ? directoryOrFilePath + : Path.Combine(directoryPath, "StdIn.cs"); + var fileToFormatInfo = FileToFormatInfo.Create( filePath, commandLineOptions.StandardInFileContents, @@ -32,7 +40,7 @@ CancellationToken cancellationToken ); var optionsProvider = await OptionsProvider.Create( - fileSystem.Path.GetDirectoryName(filePath), + directoryPath, commandLineOptions.ConfigPath, fileSystem, logger,