Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Rules/AvoidAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ private bool IsDscResourceDeclaration(CommandAst cmdAst)
{
if (GetDscResourceBody(enclosingCommand) != scriptBlock
|| !String.IsNullOrEmpty(Helper.Instance.GetCmdletNameFromAlias(enclosingCommand.GetCommandName()))
|| Helper.Instance.GetCommandInfo(enclosingCommand.GetCommandName()) != null)
|| (!String.Equals(enclosingCommand.GetCommandName(), "Node", StringComparison.OrdinalIgnoreCase)
&& Helper.Instance.GetCommandInfo(enclosingCommand.GetCommandName()) != null))
{
return false;
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/Rules/AvoidUsingAlias.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ Configuration PackageTest {
}

Context "DSC resource ASTs" {
It "does not expand nested resource names in a same-line Node declaration when node is discoverable" -skip:(!(Get-Command node -CommandType Application -ErrorAction Ignore)) {
$target = @'
{
Node localhost { Package PackageExample {} }
}
'@
$ast = [System.Management.Automation.Language.Parser]::ParseInput($target, [ref]$null, [ref]$null)
$body = $ast.EndBlock.Statements[0].PipelineElements[0].Expression.Copy()
$configuration = [System.Management.Automation.Language.ConfigurationDefinitionAst]::new(
$ast.Extent, $body, 'Resource',
[System.Management.Automation.Language.StringConstantExpressionAst]::new($ast.Extent, 'Test', 'BareWord'))
$rule = [Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidAlias]::new()

@($rule.AnalyzeScript($configuration, $null)).Count | Should -Be 0
}

It "ignores resource declarations but not executable commands" {
$target = @'
{
Expand Down
Loading