@@ -45,8 +45,7 @@ public class UseConsistentIndentation : ConfigurableRule
4545 /// property defaults to `space`.
4646 ///
4747 /// `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.
48+ /// `tab` means a tab character, `\t`.
5049 ///</summary>
5150 [ ConfigurableRuleProperty ( defaultValue : "space" ) ]
5251 public string Kind
@@ -66,6 +65,8 @@ public string Kind
6665 }
6766
6867 private bool insertSpaces ;
68+ private char indentationChar ;
69+ private int indentationLevelMultiplier ;
6970
7071 // TODO Enable auto when the rule is able to detect indentation
7172 private enum IndentationKind {
@@ -98,7 +99,14 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
9899 return Enumerable . Empty < DiagnosticRecord > ( ) ;
99100 }
100101
102+ // It is more efficient to initialize these fields in ConfigurRule method
103+ // but when the rule will enable `Auto` IndentationKind, we will anyways need to move
104+ // the setting of these variables back here after the rule detects the indentation kind for
105+ // each invocation.
101106 insertSpaces = indentationKind == IndentationKind . Space ;
107+ indentationChar = insertSpaces ? ' ' : '\t ' ;
108+ indentationLevelMultiplier = insertSpaces ? IndentationSize : 1 ;
109+
102110 var tokens = Helper . Instance . Tokens ;
103111 var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
104112 var indentationLevel = 0 ;
@@ -301,18 +309,12 @@ private int GetIndentationColumnNumber(int indentationLevel)
301309 private int GetIndentation ( int indentationLevel )
302310 {
303311 // todo if condition can be evaluated during rule configuration
304- return indentationLevel * ( insertSpaces ? this . IndentationSize : 1 ) ;
305- }
306-
307- private char GetIndentationChar ( )
308- {
309- // todo can be evaluated during rule configuration
310- return insertSpaces ? ' ' : '\t ' ;
312+ return indentationLevel * indentationLevelMultiplier ;
311313 }
312314
313315 private string GetIndentationString ( int indentationLevel )
314316 {
315- return new string ( GetIndentationChar ( ) , GetIndentation ( indentationLevel ) ) ;
317+ return new string ( indentationChar , GetIndentation ( indentationLevel ) ) ;
316318 }
317319 }
318320}
0 commit comments