File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ #if ! PSV3
2+ using System ;
23using System . Collections . Generic ;
34#if ! CORECLR
45using System . ComponentModel . Composition ;
@@ -12,7 +13,7 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
1213#if ! CORECLR
1314 [ Export ( typeof ( IScriptRule ) ) ]
1415#endif
15- class AvoidGlobalAliases : AstVisitor , IScriptRule
16+ public class AvoidGlobalAliases : AstVisitor , IScriptRule
1617 {
1718 private List < DiagnosticRecord > records ;
1819 private string fileName ;
@@ -130,3 +131,5 @@ public SourceType GetSourceType()
130131 }
131132 }
132133}
134+
135+ #endif // !PSV3
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+
4146Function Get-Count
4247{
4348 Begin {$count = 0 }
@@ -49,4 +54,5 @@ Export-ModuleMember -Function Get-ExtentText
4954Export-ModuleMember - Function Test-CorrectionExtent
5055Export-ModuleMember - Function Test-PSEditionCoreCLR
5156Export-ModuleMember - Function Test-PSEditionCoreCLRLinux
57+ Export-ModuleMember - Function Test-PSVersionV3
5258Export-ModuleMember - Function Get-Count
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments