@@ -36,13 +36,47 @@ public class UseConsistentIndentation : ConfigurableRule
3636 [ ConfigurableRuleProperty ( defaultValue : 4 ) ]
3737 public int IndentationSize { get ; protected set ; }
3838
39- [ ConfigurableRuleProperty ( defaultValue : true ) ]
40- public bool InsertSpaces { get ; protected set ; }
4139
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+ } ;
4376
4477 // TODO make this configurable
45- private readonly IndentationKind indentationKind = IndentationKind . Space ;
78+ private IndentationKind indentationKind = IndentationKind . Space ;
79+
4680
4781 /// <summary>
4882 /// Analyzes the given ast to find violations.
@@ -64,6 +98,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
6498 return Enumerable . Empty < DiagnosticRecord > ( ) ;
6599 }
66100
101+ insertSpaces = indentationKind == IndentationKind . Space ;
67102 var tokens = Helper . Instance . Tokens ;
68103 var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
69104 var indentationLevel = 0 ;
@@ -266,13 +301,13 @@ private int GetIndentationColumnNumber(int indentationLevel)
266301 private int GetIndentation ( int indentationLevel )
267302 {
268303 // todo if condition can be evaluated during rule configuration
269- return indentationLevel * ( InsertSpaces ? this . IndentationSize : 1 ) ;
304+ return indentationLevel * ( insertSpaces ? this . IndentationSize : 1 ) ;
270305 }
271306
272307 private char GetIndentationChar ( )
273308 {
274309 // todo can be evaluated during rule configuration
275- return InsertSpaces ? ' ' : '\t ' ;
310+ return insertSpaces ? ' ' : '\t ' ;
276311 }
277312
278313 private string GetIndentationString ( int indentationLevel )
0 commit comments