@@ -36,13 +36,47 @@ public class UseConsistentIndentation : ConfigurableRule
36
36
[ ConfigurableRuleProperty ( defaultValue : 4 ) ]
37
37
public int IndentationSize { get ; protected set ; }
38
38
39
- [ ConfigurableRuleProperty ( defaultValue : true ) ]
40
- public bool InsertSpaces { get ; protected set ; }
41
39
42
- private enum IndentationKind { Space , Tab } ;
40
+ // Cannot name to IndentationKind due to the enum type of the same name.
41
+ /// <summary>
42
+ /// Represents the kind of indentation to be used.
43
+ ///
44
+ /// Possible values are: `space`, `tab`. If any invalid value is given, the
45
+ /// property defaults to `space`.
46
+ ///
47
+ /// `space` means `IndentationSize` number of `space` characters are used to provide one level of indentation.
48
+ /// `tab` means a tab character, `\t`
49
+ /// `end` means the help is places the end of the function definition body.
50
+ ///</summary>
51
+ [ ConfigurableRuleProperty ( defaultValue : "space" ) ]
52
+ public string Kind
53
+ {
54
+ get
55
+ {
56
+ return indentationKind . ToString ( ) ;
57
+ }
58
+ set
59
+ {
60
+ if ( String . IsNullOrWhiteSpace ( value ) ||
61
+ ! Enum . TryParse < IndentationKind > ( value , true , out indentationKind ) )
62
+ {
63
+ indentationKind = IndentationKind . Space ;
64
+ }
65
+ }
66
+ }
67
+
68
+ private bool insertSpaces ;
69
+
70
+ // TODO Enable auto when the rule is able to detect indentation
71
+ private enum IndentationKind {
72
+ Space ,
73
+ Tab ,
74
+ // Auto
75
+ } ;
43
76
44
77
// TODO make this configurable
45
- private readonly IndentationKind indentationKind = IndentationKind . Space ;
78
+ private IndentationKind indentationKind = IndentationKind . Space ;
79
+
46
80
47
81
/// <summary>
48
82
/// Analyzes the given ast to find violations.
@@ -64,6 +98,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
64
98
return Enumerable . Empty < DiagnosticRecord > ( ) ;
65
99
}
66
100
101
+ insertSpaces = indentationKind == IndentationKind . Space ;
67
102
var tokens = Helper . Instance . Tokens ;
68
103
var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
69
104
var indentationLevel = 0 ;
@@ -266,13 +301,13 @@ private int GetIndentationColumnNumber(int indentationLevel)
266
301
private int GetIndentation ( int indentationLevel )
267
302
{
268
303
// todo if condition can be evaluated during rule configuration
269
- return indentationLevel * ( InsertSpaces ? this . IndentationSize : 1 ) ;
304
+ return indentationLevel * ( insertSpaces ? this . IndentationSize : 1 ) ;
270
305
}
271
306
272
307
private char GetIndentationChar ( )
273
308
{
274
309
// todo can be evaluated during rule configuration
275
- return InsertSpaces ? ' ' : '\t ' ;
310
+ return insertSpaces ? ' ' : '\t ' ;
276
311
}
277
312
278
313
private string GetIndentationString ( int indentationLevel )
0 commit comments