Skip to content

Commit c632ea1

Browse files
authored
If no path is found or when using the -ScriptDefinition parameter set, default to the current location for the directory search of the implicit settings file (#979)
* If no path is found or when using the -ScriptDefinition parameter set, default to the current location for the directory search of the implicit settings file * add test case * fix test so that it would actually fail if the bug got re-introduced
1 parent 606c9eb commit c632ea1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ protected override void BeginProcessing()
291291
{
292292
var settingsObj = PSSASettings.Create(
293293
settings,
294-
processedPaths == null || processedPaths.Count == 0 ? null : processedPaths[0],
294+
processedPaths == null || processedPaths.Count == 0 ? CurrentProviderLocation("FileSystem").ProviderPath : processedPaths[0],
295295
this,
296296
GetResolvedProviderPathFromPSPath);
297297
if (settingsObj != null)

Tests/Engine/Settings.tests.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ Describe "Settings Precedence" {
1414
}
1515

1616
Context "settings file is implicit" {
17-
It "runs rules from the implicit setting file" {
17+
It "runs rules from the implicit setting file using the -Path parameter set" {
1818
$violations = Invoke-ScriptAnalyzer -Path $project1Root -Recurse
1919
$violations.Count | Should -Be 1
2020
$violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases"
2121
}
2222

23+
It "runs rules from the implicit setting file using the -ScriptDefinition parameter set" {
24+
Push-Location $project1Root
25+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci; Write-Host' -Recurse
26+
Pop-Location
27+
$violations.Count | Should -Be 1
28+
$violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" `
29+
-Because 'the implicit settings file should have run only the PSAvoidUsingCmdletAliases rule but not PSAvoidUsingWriteHost'
30+
}
31+
2332
It "cannot find file if not named PSScriptAnalyzerSettings.psd1" {
2433
$violations = Invoke-ScriptAnalyzer -Path $project2Root -Recurse
2534
$violations.Count | Should -Be 2

0 commit comments

Comments
 (0)