@@ -33,6 +33,19 @@ Describe "AvoidUsingAlias" {
3333 $violations = Invoke-ScriptAnalyzer - ScriptDefinition ' verb' | Where-Object { $_.RuleName -eq $violationName }
3434 $violations.Count | Should - Be 1
3535 }
36+
37+ It " still expands aliases with resource-shaped arguments" {
38+ $target = ' icm Server01 { Get-Process }'
39+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $target - IncludeRule $violationName
40+ $violations.Count | Should - Be 1
41+ $violations [0 ].SuggestedCorrections[0 ].Text | Should - Be ' Invoke-Command'
42+ }
43+
44+ It " still adds the Get prefix to ordinary commands with resource-shaped arguments" {
45+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition ' Verb Argument {}' - IncludeRule $violationName
46+ $violations.Count | Should - Be 1
47+ $violations [0 ].SuggestedCorrections[0 ].Text | Should - Be ' Get-Verb'
48+ }
3649 }
3750
3851 Context " Violation Extent" {
@@ -65,6 +78,69 @@ Configuration MyDscConfiguration {
6578 Get-Count | `
6679 Should - Be 0
6780 }
81+
82+ It " does not expand DSC resource names during formatting" - skip:($IsLinux -or $IsMacOS ) {
83+ $target = @'
84+ Configuration PackageTest {
85+ Package PackageExample
86+ {
87+ Name = "TestPackage"
88+ }
89+ }
90+ '@
91+ $settings = @ { Rules = @ { PSAvoidUsingCmdletAliases = @ { Enable = $true } } }
92+ Invoke-ScriptAnalyzer - ScriptDefinition $target - IncludeRule $violationName |
93+ Get-Count | Should - Be 0
94+ Invoke-Formatter - ScriptDefinition $target - Settings $settings | Should - Be $target
95+ }
96+ }
97+
98+ Context " DSC resource ASTs" {
99+ It " ignores resource declarations but not executable commands" {
100+ $target = @'
101+ {
102+ Verb VerbExample {}
103+ Verb NextLineExample
104+ {
105+ }
106+ icm Server01 { Verb Argument {} }
107+ & Verb Argument {}
108+ function Get-Example {
109+ Verb Argument {}
110+ }
111+ Node localhost
112+ {
113+ Verb NestedExample {}
114+ Script ScriptExample {
115+ SetScript = {
116+ icm Server01 {}
117+ Verb Argument {}
118+ }
119+ }
120+ }
121+ $scriptProperties = @{
122+ SetScript = { Verb Argument {} }
123+ }
124+ }
125+ '@
126+ $ast = [System.Management.Automation.Language.Parser ]::ParseInput($target , [ref ]$null , [ref ]$null )
127+ $body = $ast.EndBlock.Statements [0 ].PipelineElements[0 ].Expression.Copy()
128+ $configuration = [System.Management.Automation.Language.ConfigurationDefinitionAst ]::new(
129+ $ast.Extent , $body , ' Resource' ,
130+ [System.Management.Automation.Language.StringConstantExpressionAst ]::new($ast.Extent , ' Test' , ' BareWord' ))
131+ $rule = [Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidAlias ]::new()
132+
133+ $violations = @ ($rule.AnalyzeScript ($configuration , $null ))
134+
135+ $violations.Count | Should - Be 7
136+ $violations [0 ].Extent.Text | Should - Be ' icm'
137+ $violations [1 ].Extent.Text | Should - Be ' Verb'
138+ $violations [2 ].Extent.Text | Should - Be ' Verb'
139+ $violations [3 ].Extent.Text | Should - Be ' Verb'
140+ $violations [4 ].Extent.Text | Should - Be ' icm'
141+ $violations [5 ].Extent.Text | Should - Be ' Verb'
142+ $violations [6 ].Extent.Text | Should - Be ' Verb'
143+ }
68144 }
69145
70146 Context " Settings file provides allowlist" {
0 commit comments