@@ -33,12 +33,11 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
33
33
#endif
34
34
public class UseCompatibleCmdlets : AstVisitor , IScriptRule
35
35
{
36
-
37
36
private struct RuleParameters
38
37
{
39
38
public string mode ;
40
39
public string [ ] compatibility ;
41
- public string referencePlatform ;
40
+ public string reference ;
42
41
}
43
42
44
43
private List < DiagnosticRecord > diagnosticRecords ;
@@ -50,8 +49,8 @@ private struct RuleParameters
50
49
private string scriptPath ;
51
50
private bool IsInitialized ;
52
51
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" ;
55
54
private RuleParameters ruleParameters ;
56
55
57
56
public UseCompatibleCmdlets ( )
@@ -185,14 +184,16 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
185
184
/// </summary>
186
185
private void GenerateDiagnosticRecords ( )
187
186
{
188
- bool referenceCompatibility = curCmdletCompatibilityMap [ referencePlatform ] ;
187
+ bool referenceCompatibility = curCmdletCompatibilityMap [ reference ] ;
189
188
bool requestedCompatibility = ruleParameters . compatibility . Any ( x => curCmdletCompatibilityMap [ x ] ) ;
190
189
191
190
// If the command is present in reference platform but not in any of the given platforms.
192
191
// Or if the command is not present in reference platform but present in any of the given platforms
193
192
// then declare it as an incompatible cmdlet.
194
193
// If it is present neither in reference platform nor any given platforms, then it is probably a
195
194
// 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
196
197
if ( ! ( referenceCompatibility ^ requestedCompatibility ) )
197
198
{
198
199
return ;
@@ -286,27 +287,27 @@ private void SetupCmdletsDictionary()
286
287
}
287
288
288
289
ruleParameters . compatibility = compatibilityList . ToArray ( ) ;
289
- referencePlatform = defaultReferencePlatform ;
290
+ reference = defaultReference ;
290
291
#if DEBUG
291
292
// Setup reference file
292
293
object referenceObject ;
293
294
if ( ruleArgs . TryGetValue ( "reference" , out referenceObject ) )
294
295
{
295
- referencePlatform = referenceObject as string ;
296
- if ( referencePlatform == null )
296
+ reference = referenceObject as string ;
297
+ if ( reference == null )
297
298
{
298
- referencePlatform = GetStringArgFromListStringArg ( referenceObject ) ;
299
- if ( referencePlatform == null )
299
+ reference = GetStringArgFromListStringArg ( referenceObject ) ;
300
+ if ( reference == null )
300
301
{
301
302
return ;
302
303
}
303
304
}
304
305
}
305
306
#endif
306
- ruleParameters . referencePlatform = referencePlatform ;
307
+ ruleParameters . reference = reference ;
307
308
308
309
// check if the reference file has valid platformSpec
309
- if ( ! IsValidPlatformString ( referencePlatform ) )
310
+ if ( ! IsValidPlatformString ( reference ) )
310
311
{
311
312
return ;
312
313
}
@@ -340,7 +341,7 @@ private void SetupCmdletsDictionary()
340
341
return ;
341
342
}
342
343
343
- var extentedCompatibilityList = compatibilityList . Concat ( Enumerable . Repeat ( referencePlatform , 1 ) ) ;
344
+ var extentedCompatibilityList = compatibilityList . Concat ( Enumerable . Repeat ( reference , 1 ) ) ;
344
345
foreach ( var compat in extentedCompatibilityList )
345
346
{
346
347
string psedition , psversion , os ;
@@ -371,7 +372,7 @@ private void SetupCmdletsDictionary()
371
372
/// </summary>
372
373
private bool ContainsReferenceFile ( string directory )
373
374
{
374
- return File . Exists ( Path . Combine ( directory , referencePlatform + ".json" ) ) ;
375
+ return File . Exists ( Path . Combine ( directory , reference + ".json" ) ) ;
375
376
}
376
377
377
378
/// <summary>
0 commit comments