diff --git a/Engine/Commands/InvokeScriptAnalyzerCommand.cs b/Engine/Commands/InvokeScriptAnalyzerCommand.cs index 723c540b9..ae2e0858e 100644 --- a/Engine/Commands/InvokeScriptAnalyzerCommand.cs +++ b/Engine/Commands/InvokeScriptAnalyzerCommand.cs @@ -291,7 +291,7 @@ protected override void BeginProcessing() { var settingsObj = PSSASettings.Create( settings, - processedPaths == null || processedPaths.Count == 0 ? null : processedPaths[0], + processedPaths == null || processedPaths.Count == 0 ? CurrentProviderLocation("FileSystem").ProviderPath : processedPaths[0], this, GetResolvedProviderPathFromPSPath); if (settingsObj != null) diff --git a/Tests/Engine/Settings.tests.ps1 b/Tests/Engine/Settings.tests.ps1 index 1b3d00b13..23bdf1196 100644 --- a/Tests/Engine/Settings.tests.ps1 +++ b/Tests/Engine/Settings.tests.ps1 @@ -14,12 +14,21 @@ Describe "Settings Precedence" { } Context "settings file is implicit" { - It "runs rules from the implicit setting file" { + It "runs rules from the implicit setting file using the -Path parameter set" { $violations = Invoke-ScriptAnalyzer -Path $project1Root -Recurse $violations.Count | Should -Be 1 $violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" } + It "runs rules from the implicit setting file using the -ScriptDefinition parameter set" { + Push-Location $project1Root + $violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci; Write-Host' -Recurse + Pop-Location + $violations.Count | Should -Be 1 + $violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" ` + -Because 'the implicit settings file should have run only the PSAvoidUsingCmdletAliases rule but not PSAvoidUsingWriteHost' + } + It "cannot find file if not named PSScriptAnalyzerSettings.psd1" { $violations = Invoke-ScriptAnalyzer -Path $project2Root -Recurse $violations.Count | Should -Be 2