@@ -45,8 +45,7 @@ public class UseConsistentIndentation : ConfigurableRule
45
45
/// property defaults to `space`.
46
46
///
47
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.
48
+ /// `tab` means a tab character, `\t`.
50
49
///</summary>
51
50
[ ConfigurableRuleProperty ( defaultValue : "space" ) ]
52
51
public string Kind
@@ -66,6 +65,8 @@ public string Kind
66
65
}
67
66
68
67
private bool insertSpaces ;
68
+ private char indentationChar ;
69
+ private int indentationLevelMultiplier ;
69
70
70
71
// TODO Enable auto when the rule is able to detect indentation
71
72
private enum IndentationKind {
@@ -98,7 +99,14 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
98
99
return Enumerable . Empty < DiagnosticRecord > ( ) ;
99
100
}
100
101
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.
101
106
insertSpaces = indentationKind == IndentationKind . Space ;
107
+ indentationChar = insertSpaces ? ' ' : '\t ' ;
108
+ indentationLevelMultiplier = insertSpaces ? IndentationSize : 1 ;
109
+
102
110
var tokens = Helper . Instance . Tokens ;
103
111
var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
104
112
var indentationLevel = 0 ;
@@ -301,18 +309,12 @@ private int GetIndentationColumnNumber(int indentationLevel)
301
309
private int GetIndentation ( int indentationLevel )
302
310
{
303
311
// 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 ;
311
313
}
312
314
313
315
private string GetIndentationString ( int indentationLevel )
314
316
{
315
- return new string ( GetIndentationChar ( ) , GetIndentation ( indentationLevel ) ) ;
317
+ return new string ( indentationChar , GetIndentation ( indentationLevel ) ) ;
316
318
}
317
319
}
318
320
}
0 commit comments