Skip to content

Commit

Permalink
Also format csx files (#1142)
Browse files Browse the repository at this point in the history
closes 1141
  • Loading branch information
belav committed Jan 23, 2024
1 parent 0ac449e commit b9a0f45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ await FormatPhysicalFile(
var tasks = fileSystem
.Directory.EnumerateFiles(
directoryOrFilePath,
"*.cs",
"*.*",
SearchOption.AllDirectories
)
.Where(o => o.EndsWithIgnoreCase(".cs") || o.EndsWithIgnoreCase(".csx"))
.Select(o =>
{
var normalizedPath = o.Replace("\\", "/");
Expand Down Expand Up @@ -292,7 +293,11 @@ CancellationToken cancellationToken

var fileIssueLogger = new FileIssueLogger(originalFilePath, logger);

if (!actualFilePath.EndsWithIgnoreCase(".cs") && !actualFilePath.EndsWithIgnoreCase(".cst"))
if (
!actualFilePath.EndsWithIgnoreCase(".cs")
&& !actualFilePath.EndsWithIgnoreCase(".cst")
&& !actualFilePath.EndsWithIgnoreCase(".csx")
)
{
fileIssueLogger.WriteWarning("Is an unsupported file type.");
return;
Expand Down
7 changes: 4 additions & 3 deletions Src/CSharpier.Tests/CommandLineFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public void Format_Writes_Unsupported()
.Be(@"Warning ./Unsupported.js - Is an unsupported file type.");
}

[Test]
public void Format_Writes_File_With_Directory_Path()
[TestCase(".cs")]
[TestCase(".csx")]
public void Format_Writes_File_With_Directory_Path(string extension)
{
var context = new TestContext();
const string unformattedFilePath = "Unformatted.cs";
var unformattedFilePath = $"Unformatted.{extension}";
context.WhenAFileExists(unformattedFilePath, UnformattedClassContent);

this.Format(context);
Expand Down

0 comments on commit b9a0f45

Please sign in to comment.