Skip to content

Commit 212d1f6

Browse files
author
Kapil Borle
committed
Search parameters if they are declared as keys in mof file
1 parent 8d25c79 commit 212d1f6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Rules/UseIdenticalMandatoryParametersDSC.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,24 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
5252
// todo update logic to take keys into consideration
5353
// todo write tests for same
5454
// todo update documentation
55-
var keys = GetKeys(fileName);
55+
var tempKeys = GetKeys(fileName);
56+
var keys = tempKeys == null ?
57+
new HashSet<String>() :
58+
new HashSet<string>(tempKeys, StringComparer.OrdinalIgnoreCase);
5659

5760
// Dictionary to keep track of Mandatory parameters and their presence in Get/Test/Set TargetResource cmdlets
5861
var mandatoryParameters = new Dictionary<string, List<FunctionDefinitionAst>>(StringComparer.OrdinalIgnoreCase);
5962

6063
// Loop through Set/Test/Get TargetResource DSC cmdlets
6164
foreach (FunctionDefinitionAst functionDefinitionAst in functionDefinitionAsts)
6265
{
63-
IEnumerable<Ast> funcParamAsts = functionDefinitionAst.FindAll(item => item is ParameterAst, true);
66+
IEnumerable<Ast> funcParamAsts = functionDefinitionAst.FindAll(item =>
67+
{
68+
var paramAst = item as ParameterAst;
69+
return paramAst != null &&
70+
keys.Contains(paramAst.Name.VariablePath.UserPath);
71+
},
72+
true);
6473

6574
// Loop through the parameters for each cmdlet
6675
foreach (ParameterAst paramAst in funcParamAsts)

0 commit comments

Comments
 (0)