Skip to content

Commit 8aa60a9

Browse files
committed
rough draft avoidoverwritingcmdlets working
1 parent 05f6c3d commit 8aa60a9

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

Rules/AvoidOverwritingBuiltInCmdlets.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ public class AvoidOverwritingBuiltInCmdlets : ConfigurableRule
3131
/// <summary>
3232
/// Construct an object of AvoidOverwritingBuiltInCmdlets type.
3333
/// </summary>
34-
public AvoidOverwritingBuiltInCmdlets()
34+
public AvoidOverwritingBuiltInCmdlets() : base()
3535
{
3636
initialized = false;
37+
cmdletMap = new Dictionary<string, HashSet<string>>();
38+
Enable = true; // Enable rule by default
3739
}
3840

3941

4042
[ConfigurableRuleProperty(defaultValue: "core-6.1.0-windows")]
41-
public object PowerShellVersion { get; set; }
43+
public string PowerShellVersion { get; set; }
4244

4345
private Dictionary<string, HashSet<string>> cmdletMap;
4446
private bool initialized;
@@ -70,6 +72,10 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
7072
if (!initialized)
7173
{
7274
Initialize();
75+
if (!initialized)
76+
{
77+
throw new Exception("Failed to initialize rule " + GetName());
78+
}
7379
}
7480

7581
foreach (var functionDef in functionDefinitions)
@@ -112,30 +118,7 @@ private DiagnosticRecord CreateDiagnosticRecord(string FunctionName, string PSVe
112118

113119
private void Initialize()
114120
{
115-
var psVerObjectArray = PowerShellVersion as object[];
116-
var psVerList = new List<string>();
117-
118-
if (psVerObjectArray == null)
119-
{
120-
psVerList = PowerShellVersion as List<string>;
121-
if (psVerList == null)
122-
{
123-
return;
124-
}
125-
}
126-
else
127-
{
128-
foreach (var psVer in psVerObjectArray)
129-
{
130-
var psVerString = psVer as string;
131-
if (psVerString == null)
132-
{
133-
// Ignore non-string invalid entries
134-
continue;
135-
}
136-
psVerList.Add(psVerString);
137-
}
138-
}
121+
var psVerList = PowerShellVersion.Split(',').ToList();
139122

140123
string settingsPath = Settings.GetShippedSettingsDirectory();
141124

@@ -179,7 +162,7 @@ private void ProcessDirectory(string path, IEnumerable<string> acceptablePlatfor
179162
continue;
180163
}
181164

182-
cmdletMap[fileNameWithoutExt] = GetCmdletsFromData(JObject.Parse(File.ReadAllText(filePath)));
165+
cmdletMap.Add(fileNameWithoutExt, GetCmdletsFromData(JObject.Parse(File.ReadAllText(filePath))));
183166
}
184167
}
185168

0 commit comments

Comments
 (0)