From 0f7f8b4d114eb517ec1e217b21a828e14797d457 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 25 Apr 2018 23:26:05 +0100 Subject: [PATCH 1/3] 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 --- Engine/Commands/InvokeScriptAnalyzerCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 7d5a795dd470ae27b5cc3b5dcdcf53f9c8778786 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 25 Apr 2018 23:33:45 +0100 Subject: [PATCH 2/3] add test case --- Tests/Engine/Settings.tests.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/Engine/Settings.tests.ps1 b/Tests/Engine/Settings.tests.ps1 index 1b3d00b13..57184a9fa 100644 --- a/Tests/Engine/Settings.tests.ps1 +++ b/Tests/Engine/Settings.tests.ps1 @@ -14,12 +14,18 @@ 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" { + $violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci' -Recurse + $violations.Count | Should -Be 1 + $violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" + } + It "cannot find file if not named PSScriptAnalyzerSettings.psd1" { $violations = Invoke-ScriptAnalyzer -Path $project2Root -Recurse $violations.Count | Should -Be 2 From bf5117a683bbed809eed064cb671fdddcb10cf2d Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 25 Apr 2018 23:44:20 +0100 Subject: [PATCH 3/3] fix test so that it would actually fail if the bug got re-introduced --- Tests/Engine/Settings.tests.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/Engine/Settings.tests.ps1 b/Tests/Engine/Settings.tests.ps1 index 57184a9fa..23bdf1196 100644 --- a/Tests/Engine/Settings.tests.ps1 +++ b/Tests/Engine/Settings.tests.ps1 @@ -21,9 +21,12 @@ Describe "Settings Precedence" { } It "runs rules from the implicit setting file using the -ScriptDefinition parameter set" { - $violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci' -Recurse + Push-Location $project1Root + $violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci; Write-Host' -Recurse + Pop-Location $violations.Count | Should -Be 1 - $violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" + $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" {