Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ CancellationToken cancellationToken
filePath = directoryPath;
directoryPath = fileSystem.Path.GetDirectoryName(directoryPath);
ArgumentNullException.ThrowIfNull(directoryPath);

// The directory from --stdin-path may not exist on disk.
// Walk up to the nearest existing ancestor for config resolution.
while (!fileSystem.Directory.Exists(directoryPath))
{
directoryPath = fileSystem.Path.GetDirectoryName(directoryPath);
ArgumentNullException.ThrowIfNull(directoryPath);
}

pathSupplied = true;
}
// otherwise someone is running this as a single command and not sending a path
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier.Cli/Options/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ searchingDirectory is not null
&& !dictionary.TryGetValue(searchingDirectory.FullName, out result)
)
{
if (shouldConsiderDirectory(searchingDirectory.FullName))
if (
this.fileSystem.Directory.Exists(searchingDirectory.FullName)
&& shouldConsiderDirectory(searchingDirectory.FullName)
)
{
dictionary[searchingDirectory.FullName] = result = await createFileAsync(
searchingDirectory.FullName
Expand Down
14 changes: 14 additions & 0 deletions Src/CSharpier.Tests/CommandLineFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,20 @@ public void Should_Format_StandardInput_And_Not_Consider_Gitignore_When_No_Path_
result.OutputLines.First().Should().Be(FormattedClassContent);
}

[Test]
public void Should_Format_StandardInput_When_StdinFilePath_Directory_Does_Not_Exist()
{
var context = new TestContext();
var result = Format(
context,
standardInFileContents: UnformattedClassContent,
directoryOrFilePaths: "NonExistent/SubDir/File.cs"
);

result.OutputLines.Should().ContainSingle();
result.OutputLines.First().Should().Be(FormattedClassContent);
}

[Test]
public void File_With_Mismatched_Line_Endings_In_Verbatim_String_Should_Pass_Validation()
{
Expand Down
Loading