@@ -5,13 +5,13 @@ Import-Module PSScriptAnalyzer
55Import-Module (Join-Path $testRootDirectory " PSScriptAnalyzerTestHelper.psm1" )
66
77$ruleConfiguration = @ {
8- Enable = $true
8+ Enable = $true
99 CheckHashtable = $true
1010}
1111
1212$settings = @ {
1313 IncludeRules = @ (" PSAlignAssignmentStatement" )
14- Rules = @ {
14+ Rules = @ {
1515 PSAlignAssignmentStatement = $ruleConfiguration
1616 }
1717}
@@ -26,30 +26,30 @@ $hashtable = @{
2626}
2727'@
2828
29- # Expected output after correction should be the following
30- # $hashtable = @{
31- # property1 = "value"
32- # anotherProperty = "another value"
33- # }
29+ # Expected output after correction should be the following
30+ # $hashtable = @{
31+ # property1 = "value"
32+ # anotherProperty = "another value"
33+ # }
3434
3535 $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
3636 $violations.Count | Should Be 1
3737 Test-CorrectionExtentFromContent $def $violations 1 ' ' ' '
3838 }
3939
40- It " Should find violation when assignment statements are not aligned (whitespace needs to be removed)" {
40+ It " Should find violation when assignment statements are not aligned (whitespace needs to be removed)" {
4141 $def = @'
4242$hashtable = @{
4343 property1 = "value"
4444 anotherProperty = "another value"
4545}
4646'@
4747
48- # Expected output should be the following
49- # $hashtable = @{
50- # property1 = "value"
51- # anotherProperty = "another value"
52- # }
48+ # Expected output should be the following
49+ # $hashtable = @{
50+ # property1 = "value"
51+ # anotherProperty = "another value"
52+ # }
5353
5454 $violations = Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings
5555 $violations.Count | Should Be 1
@@ -87,5 +87,37 @@ Configuration MyDscConfiguration {
8787'@
8888 Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Get-Count | Should Be 2
8989 }
90+ }
91+
92+ Context " When assignment statements are in DSC Configuration that has parse errors" {
93+ It " Sdhould find violations when assignment statements are not aligned" {
94+ $def = @'
95+ Configuration Sample_ChangeDescriptionAndPermissions
96+ {
97+ Import-DscResource -Module NonExistentModule
98+ # A Configuration block can have zero or more Node blocks
99+ Node $NodeName
100+ {
101+ # Next, specify one or more resource blocks
102+
103+ NonExistentModule MySMBShare
104+ {
105+ Ensure = "Present"
106+ Name = "MyShare"
107+ Path = "C:\Demo\Temp"
108+ ReadAccess = "author"
109+ FullAccess = "some other author"
110+ Description = "This is an updated description for this share"
111+ }
112+ }
90113}
114+ '@
115+ # This invocation will throw parse error caused by "Undefined DSC resource" because
116+ # NonExistentModule is not really avaiable to load. Therefore we set erroraction to
117+ # SilentlyContinue
118+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings - ErrorAction SilentlyContinue |
119+ Get-Count |
120+ Should Be 4
121+ }
122+ }
91123}
0 commit comments