Skip to content

Commit 911c3cf

Browse files
author
Kapil Borle
committed
Handle hashtable, array, param block in indentation rule
1 parent 63c304d commit 911c3cf

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

Rules/UseConsistentIndentation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
7171

7272
switch (token.Kind)
7373
{
74+
case TokenKind.AtCurly:
75+
case TokenKind.AtParen:
76+
case TokenKind.LParen:
7477
case TokenKind.LCurly:
7578
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine);
7679
break;
7780

81+
case TokenKind.RParen:
7882
case TokenKind.RCurly:
7983
indentationLevel = ClipNegative(indentationLevel - 1);
8084
AddViolation(token, indentationLevel, diagnosticRecords, ref onNewLine);

Tests/Rules/UseConsistentIndentation.tests.ps1

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Describe "UseConsistentIndentation" {
2828
}
2929
}
3030

31-
Context "When nested indenation of is not consistent" {
31+
Context "When nested indenation is not consistent" {
3232
BeforeAll {
3333
$def = @'
3434
function foo ($param1)
@@ -39,8 +39,62 @@ function foo ($param1)
3939
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
4040
}
4141

42-
It "Should detect a violation" {
42+
It "Should find a violation" {
4343
$violations.Count | Should Be 1
4444
}
4545
}
46+
47+
Context "When a multi-line hashtable is provided" {
48+
BeforeAll {
49+
$def = @'
50+
$hashtable = @{
51+
a = 1
52+
b = 2
53+
c = 3
54+
}
55+
'@
56+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
57+
}
58+
59+
It "Should find violations" {
60+
$violations.Count | Should Be 2
61+
}
62+
}
63+
64+
Context "When a multi-line array is provided" {
65+
BeforeAll {
66+
$def = @'
67+
$array = @(
68+
1,
69+
2,
70+
3)
71+
'@
72+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
73+
}
74+
75+
It "Should find violations" {
76+
$violations.Count | Should Be 2
77+
}
78+
}
79+
80+
Context "When a param block is provided" {
81+
BeforeAll {
82+
$def = @'
83+
param(
84+
[string] $param1,
85+
86+
[string]
87+
$param2,
88+
89+
[string]
90+
$param3
91+
)
92+
'@
93+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
94+
}
95+
96+
It "Should find violations" {
97+
$violations.Count | Should Be 4
98+
}
99+
}
46100
}

0 commit comments

Comments
 (0)