File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -298,7 +298,11 @@ private bool IsFollowingLineDscResourceBody(ScriptBlockExpressionAst body)
298298 return false ;
299299 }
300300
301- return GetDscResourceBody ( declaration ) == body ;
301+ string declarationCommandName = declaration . GetCommandName ( ) ;
302+ return GetDscResourceBody ( declaration ) == body
303+ && String . IsNullOrEmpty ( Helper . Instance . GetCmdletNameFromAlias ( declarationCommandName ) )
304+ && ( String . Equals ( declarationCommandName , "Node" , StringComparison . OrdinalIgnoreCase )
305+ || Helper . Instance . GetCommandInfo ( declarationCommandName ) == null ) ;
302306 }
303307
304308 return false ;
Original file line number Diff line number Diff line change @@ -235,6 +235,29 @@ Configuration PackageTest {
235235 }
236236 }
237237
238+ It " does not mistake following-line blocks after executable commands for DSC resources" {
239+ $target = @'
240+ {
241+ Write-Output value
242+ {
243+ Verb Argument {}
244+ }
245+ }
246+ '@
247+ $ast = [System.Management.Automation.Language.Parser ]::ParseInput($target , [ref ]$null , [ref ]$null )
248+ $body = $ast.EndBlock.Statements [0 ].PipelineElements[0 ].Expression.Copy()
249+ $configuration = [System.Management.Automation.Language.ConfigurationDefinitionAst ]::new(
250+ $ast.Extent , $body , ' Resource' ,
251+ [System.Management.Automation.Language.StringConstantExpressionAst ]::new($ast.Extent , ' Test' , ' BareWord' ))
252+ $rule = [Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidAlias ]::new()
253+
254+ $violations = @ ($rule.AnalyzeScript ($configuration , $null ))
255+
256+ $violations.Count | Should - Be 1
257+ $violations [0 ].Extent.Text | Should - Be ' Verb'
258+ $violations [0 ].SuggestedCorrections[0 ].Text | Should - Be ' Get-Verb'
259+ }
260+
238261 It " does not pair following-line blocks with commands when the block has redirections or a statement separator intervenes" {
239262 $target = @'
240263{
You can’t perform that action at this time.
0 commit comments