Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion Tests/Engine/Settings.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you, please, explain what is happening in here? Why are we pushing the $project1Root?

Copy link
Collaborator Author

@bergmeister bergmeister Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the test above I am testing that PSSA implicitly picks up the settings file (see feature description here). PSSA goes through various search paths like e.g. the supplied path (test above) or current working directory (this test/PR) or even the Desktop.

$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'gci; Write-Host' -Recurse
Pop-Location
$violations.Count | Should -Be 1
$violations[0].RuleName | Should -Be "PSAvoidUsingCmdletAliases" `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Should -BeExactly, I think it should match the case as well.

Copy link
Collaborator Author

@bergmeister bergmeister Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could use exact matching but I will need to apply that to surrounding test cases for consistency. I was wondering for a while if we should try to come up with a best practice example test template that we either document or even make a test helper method for it since nearly all PSSA tests are kind of the same...

-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
Expand Down