@@ -6,17 +6,19 @@ Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
6
6
7
7
$indentationUnit = ' '
8
8
$indentationSize = 4
9
+ $ruleConfiguration = @ {
10
+ Enable = $true
11
+ InsertSpaces = $true
12
+ IndentationSize = 4
13
+ }
14
+
9
15
$settings = @ {
10
16
IncludeRules = @ (" PSUseConsistentIndentation" )
11
- Rules = @ {
12
- PSUseConsistentIndentation = @ {
13
- Enable = $true
14
- IndentationSize = 4
15
- }
17
+ Rules = @ {
18
+ PSUseConsistentIndentation = $ruleConfiguration
16
19
}
17
20
}
18
21
19
-
20
22
Describe " UseConsistentIndentation" {
21
23
Context " When top level indentation is not consistent" {
22
24
BeforeAll {
@@ -159,13 +161,46 @@ $x = "this " + `
159
161
$violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
160
162
$violations.Count | Should Be 1
161
163
$params = @ {
162
- RawContent = $def
164
+ RawContent = $def
163
165
DiagnosticRecord = $violations [0 ]
164
166
CorrectionsCount = 1
165
- ViolationText = " `" Should be indented properly`" "
166
- CorrectionText = (New-Object - TypeName String - ArgumentList $indentationUnit , $indentationSize ) + " `" Should be indented properly`" "
167
+ ViolationText = " `" Should be indented properly`" "
168
+ CorrectionText = (New-Object - TypeName String - ArgumentList $indentationUnit , $indentationSize ) + " `" Should be indented properly`" "
167
169
}
168
170
Test-CorrectionExtentFromContent @params
169
171
}
170
172
}
173
+
174
+ Context " When tabs instead of spaces are used for indentation" {
175
+ BeforeAll {
176
+ $ruleConfiguration .' InsertSpaces' = $false
177
+ }
178
+
179
+ It " Should indent using tabs" {
180
+ $def = @'
181
+ function foo
182
+ {
183
+ get-childitem
184
+ $x=1+2
185
+ $hashtable = @{
186
+ property1 = "value"
187
+ anotherProperty = "another value"
188
+ }
189
+ }
190
+ '@
191
+ ${t} = " `t "
192
+ $expected = @"
193
+ function foo
194
+ {
195
+ ${t} get-childitem
196
+ ${t} `$ x=1+2
197
+ ${t} `$ hashtable = @{
198
+ ${t}${t} property1 = "value"
199
+ ${t}${t} anotherProperty = "another value"
200
+ ${t} }
201
+ }
202
+ "@
203
+ Invoke-Formatter - ScriptDefinition $def - Settings $settings | Should Be $expected
204
+ }
205
+ }
171
206
}
0 commit comments