File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -743,6 +743,19 @@ public async Task Format_Should_Reformat_When_Options_Change_With_Cache()
743743 result . Should ( ) . Contain ( "\n \t // break\n " ) ;
744744 }
745745
746+ [ Test ]
747+ public async Task Format_Should_Throw_With_IndentSize_Zero ( )
748+ {
749+ var unformattedContent = "public class ClassName { \n // break\n }\n " ;
750+
751+ await WriteFileAsync ( "Unformatted.cs" , unformattedContent ) ;
752+ await WriteFileAsync ( ".csharpierrc" , "indentSize: 0" ) ;
753+ var result = await new CsharpierProcess ( ) . WithArguments ( "format ." ) . ExecuteAsync ( ) ;
754+
755+ result . ExitCode . Should ( ) . Be ( 1 ) ;
756+ result . ErrorOutput . Should ( ) . Contain ( "An indent size of 0 is not valid" ) ;
757+ }
758+
746759 [ Test ]
747760 public void Format_Should_Handle_Concurrent_Processes ( )
748761 {
Original file line number Diff line number Diff line change @@ -4,10 +4,24 @@ namespace CSharpier.Core;
44
55internal class PrinterOptions ( Formatter formatter )
66{
7+ private int indentSize = formatter == Formatter . XML ? 2 : 4 ;
78 public bool IncludeAST { get ; init ; }
89 public bool IncludeDocTree { get ; init ; }
910 public bool UseTabs { get ; set ; }
10- public int IndentSize { get ; set ; } = formatter == Formatter . XML ? 2 : 4 ;
11+
12+ public int IndentSize
13+ {
14+ get => this . indentSize ;
15+ set
16+ {
17+ if ( value <= 0 )
18+ {
19+ throw new ArgumentException ( "An indent size of 0 is not valid" ) ;
20+ }
21+ this . indentSize = value ;
22+ }
23+ }
24+
1125 public int Width { get ; set ; } = 100 ;
1226 public EndOfLine EndOfLine { get ; set ; } = EndOfLine . Auto ;
1327 public bool TrimInitialLines { get ; init ; } = true ;
You can’t perform that action at this time.
0 commit comments