@@ -33,12 +33,11 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
3333#endif
3434 public class UseCompatibleCmdlets : AstVisitor , IScriptRule
3535 {
36-
3736 private struct RuleParameters
3837 {
3938 public string mode ;
4039 public string [ ] compatibility ;
41- public string referencePlatform ;
40+ public string reference ;
4241 }
4342
4443 private List < DiagnosticRecord > diagnosticRecords ;
@@ -50,8 +49,8 @@ private struct RuleParameters
5049 private string scriptPath ;
5150 private bool IsInitialized ;
5251 private bool hasInitializationError ;
53- private string referencePlatform ;
54- private readonly string defaultReferencePlatform = "desktop-5.1.14393.206-windows" ;
52+ private string reference ;
53+ private readonly string defaultReference = "desktop-5.1.14393.206-windows" ;
5554 private RuleParameters ruleParameters ;
5655
5756 public UseCompatibleCmdlets ( )
@@ -185,14 +184,16 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
185184 /// </summary>
186185 private void GenerateDiagnosticRecords ( )
187186 {
188- bool referenceCompatibility = curCmdletCompatibilityMap [ referencePlatform ] ;
187+ bool referenceCompatibility = curCmdletCompatibilityMap [ reference ] ;
189188 bool requestedCompatibility = ruleParameters . compatibility . Any ( x => curCmdletCompatibilityMap [ x ] ) ;
190189
191190 // If the command is present in reference platform but not in any of the given platforms.
192191 // Or if the command is not present in reference platform but present in any of the given platforms
193192 // then declare it as an incompatible cmdlet.
194193 // If it is present neither in reference platform nor any given platforms, then it is probably a
195194 // non-builtin command and hence do not declare it as an incompatible cmdlet.
195+ // Since we do not check for aliases, the XOR-ing will also make sure that aliases are not flagged
196+ // as they will be found neither in reference platform nor in given platforms
196197 if ( ! ( referenceCompatibility ^ requestedCompatibility ) )
197198 {
198199 return ;
@@ -286,27 +287,27 @@ private void SetupCmdletsDictionary()
286287 }
287288
288289 ruleParameters . compatibility = compatibilityList . ToArray ( ) ;
289- referencePlatform = defaultReferencePlatform ;
290+ reference = defaultReference ;
290291#if DEBUG
291292 // Setup reference file
292293 object referenceObject ;
293294 if ( ruleArgs . TryGetValue ( "reference" , out referenceObject ) )
294295 {
295- referencePlatform = referenceObject as string ;
296- if ( referencePlatform == null )
296+ reference = referenceObject as string ;
297+ if ( reference == null )
297298 {
298- referencePlatform = GetStringArgFromListStringArg ( referenceObject ) ;
299- if ( referencePlatform == null )
299+ reference = GetStringArgFromListStringArg ( referenceObject ) ;
300+ if ( reference == null )
300301 {
301302 return ;
302303 }
303304 }
304305 }
305306#endif
306- ruleParameters . referencePlatform = referencePlatform ;
307+ ruleParameters . reference = reference ;
307308
308309 // check if the reference file has valid platformSpec
309- if ( ! IsValidPlatformString ( referencePlatform ) )
310+ if ( ! IsValidPlatformString ( reference ) )
310311 {
311312 return ;
312313 }
@@ -340,7 +341,7 @@ private void SetupCmdletsDictionary()
340341 return ;
341342 }
342343
343- var extentedCompatibilityList = compatibilityList . Concat ( Enumerable . Repeat ( referencePlatform , 1 ) ) ;
344+ var extentedCompatibilityList = compatibilityList . Concat ( Enumerable . Repeat ( reference , 1 ) ) ;
344345 foreach ( var compat in extentedCompatibilityList )
345346 {
346347 string psedition , psversion , os ;
@@ -371,7 +372,7 @@ private void SetupCmdletsDictionary()
371372 /// </summary>
372373 private bool ContainsReferenceFile ( string directory )
373374 {
374- return File . Exists ( Path . Combine ( directory , referencePlatform + ".json" ) ) ;
375+ return File . Exists ( Path . Combine ( directory , reference + ".json" ) ) ;
375376 }
376377
377378 /// <summary>
0 commit comments