Skip to content

Commit 3212a20

Browse files
author
Kapil Borle
committed
Fix discrepancy in loading custom rules
Loading an external rule module with version errors out on PSv4. But it works on PSv5. So we remove the sample rule with version from the glob pattern by renaming it.
1 parent 04a424f commit 3212a20

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//
1+

2+
//
23
// Copyright (c) Microsoft Corporation.
34
//
45
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Describe "Test importing correct customized rules" {
108108

109109
It "will show the custom rules when given glob with recurse switch" {
110110
$customizedRulePath = Get-ScriptAnalyzerRule -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule* | Where-Object {$_.RuleName -eq $measure}
111-
$customizedRulePath.Count | Should be 4
111+
$customizedRulePath.Count | Should be 3
112112
}
113113
}
114114

@@ -147,7 +147,7 @@ Describe "Test importing correct customized rules" {
147147

148148
It "will show the custom rules when given glob with recurse switch" {
149149
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule* | Where-Object {$_.Message -eq $message}
150-
$customizedRulePath.Count | Should be 4
150+
$customizedRulePath.Count | Should be 3
151151
}
152152

153153
It "Using IncludeDefaultRules Switch with CustomRulePath" {
@@ -164,23 +164,26 @@ Describe "Test importing correct customized rules" {
164164
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
165165
$customizedRulePath.Count | Should Be 1
166166
}
167+
168+
if ($PSVersionTable.PSVersion -ge [Version]'5.0')
169+
{
170+
It "loads custom rules that contain version in their path" {
171+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\VersionedSampleRule\SampleRuleWithVersion
172+
$customizedRulePath.Count | Should Be 1
167173

168-
It "loads custom rules that contain version in their path" {
169-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\SampleRuleWithVersion\SampleRuleWithVersion
170-
$customizedRulePath.Count | Should Be 1
171-
172-
$customizedRulePath = Get-ScriptAnalyzerRule -CustomRulePath $directory\SampleRuleWithVersion\SampleRuleWithVersion
173-
$customizedRulePath.Count | Should Be 1
174-
}
174+
$customizedRulePath = Get-ScriptAnalyzerRule -CustomRulePath $directory\VersionedSampleRulen\SampleRuleWithVersion
175+
$customizedRulePath.Count | Should Be 1
176+
}
175177

176-
It "loads custom rules that contain version in their path with the RecurseCustomRule switch" {
177-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\SampleRuleWithVersion -RecurseCustomRulePath
178-
$customizedRulePath.Count | Should Be 1
178+
It "loads custom rules that contain version in their path with the RecurseCustomRule switch" {
179+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\VersionedSampleRulen -RecurseCustomRulePath
180+
$customizedRulePath.Count | Should Be 1
179181

180-
$customizedRulePath = Get-ScriptAnalyzerRule -CustomRulePath $directory\SampleRuleWithVersion -RecurseCustomRulePath
181-
$customizedRulePath.Count | Should Be 1
182+
$customizedRulePath = Get-ScriptAnalyzerRule -CustomRulePath $directory\VersionedSampleRulen -RecurseCustomRulePath
183+
$customizedRulePath.Count | Should Be 1
182184

183-
}
185+
}
186+
}
184187
}
185188

186189
}

0 commit comments

Comments
 (0)