Skip to content

Commit

Permalink
Include the "IncludeGenerated" option in the SDK
Browse files Browse the repository at this point in the history
closes #1215
  • Loading branch information
belav committed Mar 24, 2024
1 parent 2173bdc commit 8491c30
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
28 changes: 28 additions & 0 deletions Src/CSharpier.Tests/CodeFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ public void Format_Should_Use_EndOfLine()
result.Code.Should().Be("var someVariable = someValue;\r\n");
}

[Test]
public void Format_Should_Ignore_Generated_Files()
{
var code = """
// <auto-generated>
var someVariable = someValue;
""";
var result = CodeFormatter.Format(code, new CodeFormatterOptions());

result.Code.Should().Be(code);
}

[Test]
public void Format_Should_Format_Generated_Files()
{
var code = """
// <auto-generated>
var someVariable = someValue;

""";
var result = CodeFormatter.Format(
code,
new CodeFormatterOptions { IncludeGenerated = true }
);

result.Code.Should().Be(code.Replace(" = ", " = "));
}

[TestCase("\n")]
[TestCase("\r\n")]
public void Format_Should_Get_Line_Endings_With_SyntaxTree(string lineEnding)
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier/CodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static CodeFormatterResult Format(string code, CodeFormatterOptions? opti
Width = options.Width,
UseTabs = options.IndentStyle == IndentStyle.Tabs,
TabWidth = options.IndentSize,
EndOfLine = options.EndOfLine
EndOfLine = options.EndOfLine,
IncludeGenerated = options.IncludeGenerated
},
cancellationToken
);
Expand Down
1 change: 1 addition & 0 deletions Src/CSharpier/CodeFormatterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class CodeFormatterOptions
public IndentStyle IndentStyle { get; init; } = IndentStyle.Spaces;
public int IndentSize { get; init; } = 4;
public EndOfLine EndOfLine { get; init; } = EndOfLine.Auto;
public bool IncludeGenerated { get; init; }
}

public enum IndentStyle
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

CSharpier.CodeFormatterOptions.IncludeGenerated.get -> bool
CSharpier.CodeFormatterOptions.IncludeGenerated.init -> void

0 comments on commit 8491c30

Please sign in to comment.