Skip to content

Commit 4b33bdb

Browse files
author
Kapil Borle
committed
Remove PSAvoidGlobalAliases rule from PSv3 support
The rules uses StaticParameterBinder.BindCommand which is present in v4 and above.
1 parent 3301aa1 commit 4b33bdb

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

Rules/AvoidGlobalAliases.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if !PSV3
2+
using System;
23
using System.Collections.Generic;
34
#if !CORECLR
45
using System.ComponentModel.Composition;
@@ -130,3 +131,5 @@ public SourceType GetSourceType()
130131
}
131132
}
132133
}
134+
135+
#endif // !PSV3

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ Describe "Test Name parameters" {
6262
It "get Rules with no parameters supplied" {
6363
$defaultRules = Get-ScriptAnalyzerRule
6464
$expectedNumRules = 45
65-
if ((Test-PSEditionCoreClr))
65+
if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3))
6666
{
67+
# for PSv3 PSAvoidGlobalAliases is not shipped because
68+
# it uses StaticParameterBinder.BindCommand which is
69+
# available only on PSv4 and above
70+
# for PowerShell Core, PSUseSingularNouns is not
71+
# shipped because it uses APIs that are not present
72+
# in dotnet core.
6773
$expectedNumRules = 44
6874
}
6975
$defaultRules.Count | Should be $expectedNumRules

Tests/PSScriptAnalyzerTestHelper.psm1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Function Test-PSEditionCoreCLRLinux
3838
(Test-PSEditionCoreCLR) -and $IsLinux
3939
}
4040

41+
Function Test-PSVersionV3
42+
{
43+
$PSVersionTable.PSVersion.Major -eq 3
44+
}
45+
4146
Function Get-Count
4247
{
4348
Begin {$count = 0}
@@ -49,4 +54,5 @@ Export-ModuleMember -Function Get-ExtentText
4954
Export-ModuleMember -Function Test-CorrectionExtent
5055
Export-ModuleMember -Function Test-PSEditionCoreCLR
5156
Export-ModuleMember -Function Test-PSEditionCoreCLRLinux
57+
Export-ModuleMember -Function Test-PSVersionV3
5258
Export-ModuleMember -Function Get-Count

Tests/Rules/AvoidGlobalAliases.tests.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
Import-Module PSScriptAnalyzer
1+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
2+
$testRootDirectory = Split-Path -Parent $directory
3+
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
4+
if ((Test-PSVersionV3))
5+
{
6+
return
7+
}
8+
9+
Import-Module PSScriptAnalyzer
210

311
$AvoidGlobalAliasesError = "Avoid creating aliases with a Global scope."
412
$violationName = "PSAvoidGlobalAliases"
5-
6-
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
713
$violations = Invoke-ScriptAnalyzer $directory\AvoidGlobalAliases.psm1 | Where-Object {$_.RuleName -eq $violationName}
814
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidGlobalAliasesNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
915

0 commit comments

Comments
 (0)