Skip to content

Commit cabfc17

Browse files
Copilotbergmeister
andauthored
Fix DSC resource alias classification
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent b64eda7 commit cabfc17

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎Rules/AvoidAlias.cs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
119119
}
120120

121121
string cmdletNameIfCommandNameWasAlias = Helper.Instance.GetCmdletNameFromAlias(commandName);
122+
bool isDscResourceDeclaration = IsDscResourceDeclaration(cmdAst);
123+
if (isDscResourceDeclaration
124+
&& (String.IsNullOrEmpty(cmdletNameIfCommandNameWasAlias) || cmdAst.CommandElements.Count == 2))
125+
{
126+
continue;
127+
}
128+
122129
if (!String.IsNullOrEmpty(cmdletNameIfCommandNameWasAlias))
123130
{
124131
yield return new DiagnosticRecord(
@@ -133,11 +140,6 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
133140
continue;
134141
}
135142

136-
if (IsDscResourceDeclaration(cmdAst))
137-
{
138-
continue;
139-
}
140-
141143
// If we find match of any kind, do not continue with the Get-{commandname} check
142144
if ( Helper.Instance.GetCommandInfo(commandName) != null ) {
143145
continue;

‎Tests/Rules/AvoidUsingAlias.tests.ps1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Configuration PackageTest {
103103
Verb NextLineExample
104104
{
105105
}
106+
gci ResourceAliasExample
107+
{
108+
Name = "Example"
109+
}
106110
icm Server01 { Verb Argument {} }
107111
& Verb Argument {}
108112
function Get-Example {

0 commit comments

Comments
 (0)