Skip to content

Commit 7e4a2f8

Browse files
author
Kapil Borle
committed
Read updated json from usecompatiblecmdlets rule
1 parent de8338d commit 7e4a2f8

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Rules/UseCompatibleCmdlets.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using System.Text.RegularExpressions;
2222
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
2323

24-
using Newtonsoft.Json;
24+
using Newtonsoft.Json.Linq;
2525

2626
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2727
{
@@ -209,28 +209,23 @@ private void ProcessDirectory(string path)
209209
continue;
210210
}
211211

212-
psCmdletMap[fileNameWithoutExt] = GetCmdletsFromData(JsonConvert.DeserializeObject(File.ReadAllText(filePath)));
212+
psCmdletMap[fileNameWithoutExt] = GetCmdletsFromData(JObject.Parse(File.ReadAllText(filePath)));
213213
}
214214
}
215215

216216
private HashSet<string> GetCmdletsFromData(dynamic deserializedObject)
217217
{
218218
var cmdlets = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
219-
foreach (var module in deserializedObject)
219+
dynamic modules = deserializedObject.Modules;
220+
foreach (var module in modules)
220221
{
221-
if (module.HasValues == false)
222+
foreach (var cmdlet in module.ExportedCommands)
222223
{
223-
continue;
224-
}
225-
226-
foreach (var cmdlet in module.Value)
227-
{
228-
if (cmdlet.Name != null)
229-
{
230-
cmdlets.Add(cmdlet.Name);
231-
}
224+
var name = cmdlet.Name.Value as string;
225+
cmdlets.Add(name);
232226
}
233227
}
228+
234229
return cmdlets;
235230
}
236231

0 commit comments

Comments
 (0)