@@ -31,14 +31,16 @@ public class AvoidOverwritingBuiltInCmdlets : ConfigurableRule
31
31
/// <summary>
32
32
/// Construct an object of AvoidOverwritingBuiltInCmdlets type.
33
33
/// </summary>
34
- public AvoidOverwritingBuiltInCmdlets ( )
34
+ public AvoidOverwritingBuiltInCmdlets ( ) : base ( )
35
35
{
36
36
initialized = false ;
37
+ cmdletMap = new Dictionary < string , HashSet < string > > ( ) ;
38
+ Enable = true ; // Enable rule by default
37
39
}
38
40
39
41
40
42
[ ConfigurableRuleProperty ( defaultValue : "core-6.1.0-windows" ) ]
41
- public object PowerShellVersion { get ; set ; }
43
+ public string PowerShellVersion { get ; set ; }
42
44
43
45
private Dictionary < string , HashSet < string > > cmdletMap ;
44
46
private bool initialized ;
@@ -70,6 +72,10 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
70
72
if ( ! initialized )
71
73
{
72
74
Initialize ( ) ;
75
+ if ( ! initialized )
76
+ {
77
+ throw new Exception ( "Failed to initialize rule " + GetName ( ) ) ;
78
+ }
73
79
}
74
80
75
81
foreach ( var functionDef in functionDefinitions )
@@ -112,30 +118,7 @@ private DiagnosticRecord CreateDiagnosticRecord(string FunctionName, string PSVe
112
118
113
119
private void Initialize ( )
114
120
{
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 ( ) ;
139
122
140
123
string settingsPath = Settings . GetShippedSettingsDirectory ( ) ;
141
124
@@ -179,7 +162,7 @@ private void ProcessDirectory(string path, IEnumerable<string> acceptablePlatfor
179
162
continue ;
180
163
}
181
164
182
- cmdletMap [ fileNameWithoutExt ] = GetCmdletsFromData ( JObject . Parse ( File . ReadAllText ( filePath ) ) ) ;
165
+ cmdletMap . Add ( fileNameWithoutExt , GetCmdletsFromData ( JObject . Parse ( File . ReadAllText ( filePath ) ) ) ) ;
183
166
}
184
167
}
185
168
0 commit comments