Skip to content

Commit 0fc6447

Browse files
author
Kapil Borle
authored
Merge pull request #649 from PowerShell/kapilmb/ExternalRuleScriptPath
Fix external rules ScriptPath property
2 parents 5d0ff03 + 7355f6b commit 0fc6447

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
19931993
}
19941994
}
19951995

1996-
foreach (var ruleRecord in this.GetExternalRecord(scriptAst, scriptTokens, exRules.ToArray(), fileName))
1996+
foreach (var ruleRecord in this.GetExternalRecord(scriptAst, scriptTokens, exRules.ToArray(), filePath))
19971997
{
19981998
var records = SuppressRule(ruleSuppressions, ruleRecord);
19991999
foreach (var record in records.Item2)

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ Describe "Test importing correct customized rules" {
150150
$customizedRulePath.Count | Should Be 1
151151
}
152152

153+
It "will set ScriptName property to the target file name" {
154+
$violations = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule
155+
$violations[0].ScriptName | Should Be 'TestScript.ps1'
156+
}
157+
158+
It "will set ScriptPath property to the target file path" {
159+
$violations = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule
160+
$expectedScriptPath = Join-Path $directory 'TestScript.ps1'
161+
$violations[0].ScriptPath | Should Be $expectedScriptPath
162+
}
163+
153164
if (!$testingLibraryUsage)
154165
{
155166
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {

0 commit comments

Comments
 (0)